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

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

Open line0 opened this issue 3 years ago • 5 comments
trafficstars

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.

line0 avatar Jul 07 '22 15:07 line0

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 :)

ThaNarie avatar Jul 11 '22 09:07 ThaNarie

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

pyrossh avatar May 11 '23 17:05 pyrossh

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

mariusGundersen avatar Sep 13 '23 08:09 mariusGundersen

@jonathantneal friendly reminder

shrpne avatar Mar 05 '24 16:03 shrpne

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

ThaNarie avatar Mar 08 '24 18:03 ThaNarie

I've applied some of these changes and released this as version 12.

Thank you for submitting this patch. I didn't merge this PR because there was too much that needed updating and it caused too many merge conflicts.

Please let me know if everything is working as expected in version 12: https://github.com/csstools/postcss-normalize/commit/0e4f3eb55eff7b327ed30db7a4e76720ff94eba4#diff-bc69bfbd1c28ef50e09027241a08a1de58630d73355aaf7bf571df874ebfaeb6

romainmenke avatar Sep 07 '24 15:09 romainmenke