parcel: Cannot import less or styl in TypeScript files (Cannot find module 'less')
๐ bug report
I am trying to import a less or styl file, but although the documentation says they are supported out of the box, the plugin throws an error:
https://github.com/aminya/solid-simple-table/tree/less
@parcel/transformer-less: Cannot find module 'less' from 'C:solid-tablesrc'
Error: Cannot find module 'less' from 'C:\\solid-table\src'
at C:\\solid-table\node_modules\resolve\lib\async.js:116:35
at processDirs (C:\\solid-table\node_modules\resolve\lib\async.js:269:39)
at isdir (C:\\solid-table\node_modules\resolve\lib\async.js:276:32)
at isDirectory (C:\\solid-table\node_modules\@parcel\utils\lib\resolve.js:92:9)
Also the printing of the paths seems to be broken for Windows ('C:solid-tablesrc'
).
๐ Configuration (.babelrc, package.json, cli command)
babel
{
"presets": ["babel-preset-solid", "@babel/preset-typescript", "@parcel/babel-preset-env"],
"plugins": ["@parcel/babel-plugin-transform-runtime"]
}
package.json:
"main": "dist/SimpleTable.js",
"module": "dist/SimpleTable.module.js",
"scripts": {
"dev": "cross-env NODE_ENV=development parcel watch src/SimpleTable.tsx",
"build": "cross-env NODE_ENV=production parcel build src/SimpleTable.tsx"
}
"targets": {
"main": {
"context": "browser",
"engines": {
"browsers": "> 0.25%"
},
"includeNodeModules": true,
"isLibrary": true
},
"module": {
"context": "browser",
"engines": {
"browsers": "Chrome 76"
},
"includeNodeModules": false,
"isLibrary": true
}
}
๐ค Expected Behavior
Transform and import less file
๐ฏ Current Behavior
Throws an error
๐ Possible Solution
npm install --save-dev less
๐ฆ Context
๐ป Code Sample
https://github.com/aminya/solid-simple-table/tree/less
๐ Your Environment
Software | Version(s) |
---|---|
Parcel | ^2.0.0-nightly.490 |
Node | 15.5.0 |
npm/Yarn | 6.14.8 |
Operating System | Win 10 |
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (14 by maintainers)
IMO auto install is a convenience for fast development iteration. It is not something that should be relied on for production builds, where consistency of versions is more important. When using auto install in development, the installed package should already be added to a yarn.lock or package-lock.json depending on your package manager. Then, when doing production builds, you will get a consistent version. Iโm not sure I see the need for auto install in production, and either way I donโt think itโs a good idea.
But
parcel build
= production mode.We should probably change the message if autoinstall is disabled to rather be โitโs needed, please install this yourself because autoinstall is disabledโ.
I think autoinstall now works in the production builds too.
Is there an option/flag to enable auto-install back? I donโt like this default option.
If someone is supposed to install a dependency for building, then what is the benefit of auto-install anyway? You are just deferring the installation until someone runs the Parcel build and hits the error.
The packages that are auto-installed should be locked with Parcelโs version. To me, Parcel 2-nightly.89 means Less 4.0.0. If auto-install always installs the latest package, then we have a problem here.