Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

line0
Copy link

@line0 line0 commented Jul 7, 2022

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
Copy link

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
Copy link

pyrossh commented May 11, 2023

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

@mariusGundersen
Copy link

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

@shrpne
Copy link

shrpne commented Mar 5, 2024

@jonathantneal friendly reminder

@ThaNarie
Copy link

ThaNarie commented Mar 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants