postcss / postcss-load-config

Autoload Config for PostCSS
MIT License
638 stars 71 forks source link

v.4.0.0 ESM err on Windows 11 #237

Closed Krutsch closed 2 years ago

Krutsch commented 2 years ago

Node.js version 17.9.0

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
    at new NodeError (node:internal/errors:372:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1075:11)
    at defaultResolve (node:internal/modules/esm/resolve:1155:3)
    at ESMLoader.resolve (node:internal/modules/esm/loader:604:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
    at ESMLoader.import (node:internal/modules/esm/loader:404:22)
    at importModuleDynamically (node:internal/modules/cjs/loader:1037:29)
    at importModuleDynamicallyWrapper (node:internal/vm/module:437:21)
    at importModuleDynamically (node:vm:381:46)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

Code to reproduce: type module in package.json. postcss.config.cjs:

const isProduction = process.env.NODE_ENV === "production";
const tailwindcss = require("./tailwind.config.cjs");

module.exports = {
  plugins: {
    tailwindcss,
    ...(isProduction
      ? {
          cssnano: {
            preset: "advanced",
          },
        }
      : {}),
  },
};

let { plugins, options, file: postcssFile } = await postcssrc({});

This did not error in the verion before

ai commented 2 years ago

@michael42 seems like ESM loader has a problem with Windows. We may need pathToFileURL.

michael42 commented 2 years ago

Oh, that sounds plausible. I do all my development on Linux, so I can't verify that right away, but others also had the same issue. I'll prepare a PR, but testing that is a bit weird because pathToFileURL is platform-specific (since C:\abc.txt is a completely valid file name on Linux).

michael42 commented 2 years ago

I did leave out trying to explicitly test that in the PR, since that would be pretty cumbersome and I'm almost sure the tests were already failing on Windows before the fix. So I think it would be best to just run the existing tests on Windows, if that's not too much trouble.

Krutsch commented 2 years ago

Had to change the pattern for uvu locally but can confirm it works 👍🏼

ai commented 2 years ago

The fix was released in 4.0.1.

@michael42 thanks for the fast and great job.