postcss-normalize
postcss-normalize copied to clipboard
Fix resolution of @csstools/normalize.css path when using ESM
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.
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 :)
Yep failing for me as well. Trying to use esm module resolution.
I've come across this problem too, any chance this pr can be merged soon?
@jonathantneal friendly reminder
FYI; Another reason for this error to happen, is if you use spaces in your folder name.
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