postcss-cli icon indicating copy to clipboard operation
postcss-cli copied to clipboard

Version 9 is throwing exception on ESM loader

Open MarcLongJoyride opened this issue 5 years ago • 8 comments

I am getting the following error on node v12.18.0 in WSL 2.0 (Windows version 10.0.19043.1237)

(node:2975) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:54
    internalBinding('errors').triggerUncaughtException(
                              ^
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:720:11)
    at Loader.resolve (internal/modules/esm/loader.js:97:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)
    at link (internal/modules/esm/module_job.js:41:36) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

If I run ./node_modules/.bin/postcss, I am able to limit this error down specifically to postcss.

Downgrading from postcss-cli 9.0.0 to 8.x resolves the issue.

(Edit: also see the issue in v14 of node)

MarcLongJoyride avatar Sep 29 '21 23:09 MarcLongJoyride

Are you using --use?

RyanZim avatar Sep 30 '21 13:09 RyanZim

I got the same problem with 9.0.0 and 9.0.1 -- but only when building on Netlify. The same build works fine locally and with GitHub Actions.

Not using --use, my command is plain and simple: postcss src/css/main.css --output dist/css/main.css

This is what the postcss config looks like:

const mediaVariables = require('postcss-media-variables')

module.exports = {
  plugins: [
    require('autoprefixer'),
    require('postcss-import'),
    require('postcss-nesting'),
    mediaVariables,
    require('postcss-custom-media'),
    require('postcss-calc'),
    mediaVariables,
  ],
}

All packages are current:

    "autoprefixer": "10.3.6",
    "postcss": "8.3.8",
    "postcss-calc": "8.0.0",
    "postcss-cli": "9.0.1",
    "postcss-custom-media": "8.0.0",
    "postcss-import": "14.0.2",
    "postcss-media-variables": "2.0.1",
    "postcss-nesting": "8.0.1",

dennisreimann avatar Sep 30 '21 18:09 dennisreimann

Oh, just noticed; you're on Node v12.18; technically, ESM is only supported in Node v12.20+ I just assumed everyone would be on the latest Node v12 if they were using v12

RyanZim avatar Sep 30 '21 19:09 RyanZim

@RyanZim Thanks for the clarification -- Netlify is by default still using v12.18, that's the cause there.

dennisreimann avatar Oct 01 '21 07:10 dennisreimann

Same issue on Cloudflare Pages. It runs (as of now) 12.18.0, so the procedure is to add an environment variable with the key of NODE_VERSION and a value of at least 12.20.0. (Vercel and Render use 14.x AFAIK.)

brycewray avatar Oct 03 '21 19:10 brycewray

I had the same issue on postcss 8.3.9 and node 14.12.0. After upgrading to node 14.18, it worked.

internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. Received protocol 'node:'
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:756:11)
    at Loader.resolve (internal/modules/esm/loader.js:85:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:229:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:51:40)
    at link (internal/modules/esm/module_job.js:50:36) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

kintarowins avatar Oct 10 '21 10:10 kintarowins

Same issue on Cloudflare Pages. It runs (as of now) 12.18.0, so the procedure is to add an environment variable with the key of NODE_VERSION and a value of at least 12.20.0. (Vercel and Render use 14.x AFAIK.)

This solved the issue on my side. Thank you so much!

ensodx-snedzhip avatar Sep 28 '22 22:09 ensodx-snedzhip

As @brycewray points out above (thanks 👍), Cloudflare pages runs on Node 12.18.0 by default. It can, however, be bumped up until 17.x, according to https://developers.cloudflare.com/pages/platform/build-configuration/#language-support-and-tools

And as an alternative to what @brycewray suggest, creating an .nvmrc file in the root of the repo works just as well. I installed Node 17.9.1 (the most up to date possible) and this error is gone.

Once Cloudflare pages v2 comes out, and according to this discussion, it will be possible to install Node 18.

pmpinto avatar Nov 16 '22 18:11 pmpinto