csstools / postcss-normalize

Use the parts of normalize.css (or sanitize.css) you need from your browserslist
Creative Commons Zero v1.0 Universal
816 stars 40 forks source link

Fix resolution of @csstools/normalize.css path when using ESM #65

Open line0 opened 2 years ago

line0 commented 2 years ago

When using the postcss-normalize ESM export, the resolution of the @csstools/normalize.css package location fails for me with an Error: Cannot find module '@csstools/normalize.css'.

Not entirely sure if this is due to using yarn workspaces or a Node version incompatibility, but using the official module.createRequire() and requireResolve() APIs instead of undocumented internals fixes the issue. Confirmed to work on Node v18, but the APIs are available all the way down to Node v12, so this shouldn't break anything.

Also had to fix the tests to reflect changes in @csstools/normalize.css v12.0.0.

ThaNarie commented 2 years ago

This failed for me as well, but only on Windows.

The issue seems that Module._nodeModulePaths creates duplicate drive paths for input path /D:/projects/pota-test/pota-project/node_modules/postcss-normalize:

  'D:\\D:\\projects\\pota-test\\pota-project\\node_modules\\postcss-normalize\\node_modules',
  'D:\\D:\\projects\\pota-test\\pota-project\\node_modules',
  'D:\\D:\\projects\\pota-test\\node_modules',
  'D:\\D:\\projects\\node_modules',
  'D:\\D:\\node_modules',
  'D:\\D\\node_modules',
  'D:\\node_modules'

When I enter the correct non-duplicated D:\\projects\\pota-test\\pota-project\\node_modules myself manually, it does work.

Either way, removing unsupported undocumented internal function, and replacing them with the correct ones, seems like the best option :)

pyrossh commented 1 year ago

Yep failing for me as well. Trying to use esm module resolution.

mariusGundersen commented 10 months ago

I've come across this problem too, any chance this pr can be merged soon?

shrpne commented 5 months ago

@jonathantneal friendly reminder

ThaNarie commented 4 months ago

FYI; Another reason for this error to happen, is if you use spaces in your folder name.