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)

Most upvoted comments

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.

Because we probably want reproducible builds in production

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.