-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Take precedence of NODE_PATH when resolving node_modules directories #4453
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4453 +/- ##
=======================================
Coverage 56.74% 56.74%
=======================================
Files 189 189
Lines 6485 6485
Branches 3 3
=======================================
Hits 3680 3680
Misses 2804 2804
Partials 1 1
Continue to review full report at Codecov.
|
@kittens - Can you provide a bit more context on this change? We bisected jest module resolution errors to this commit, specifically for our team members whose NODE_PATH variable contains one or more paths that don't exist on their system. Before this change, the nonexistent paths would be further down the resolution paths array and the error wouldn't occur. In a related note, jest should probably skip resolving modules in nonexistent directories instead of fail with the following error:
Edit: looking more at this, I think the correct solution is to throw a clearer error including the attempted module resolution path. |
…tion directory does not exist Summary: A recent change to take precedence of NODE_PATH for module resolution (jestjs#4453) made this issue more likely to occur since NODE_PATH could contain non-existent directories. While this could have occurred prior to the change, it was less likely since it is more common that modules are in local `node_modules`. Either way, non-existent directories should be treated the same way as non-existent files during module resolution. The equivalent case for `statSync` returning `ENOENT` for files is `ENOTDIR` for directories. We may want to add `ENOTDIR` to `isFile` as well. Test Plan: 1. `yarn test` 2. Link cli into another project, set NODE_PATH to non-existent directories, no longer see cryptic `Cannot find module` error. Instead, it now resolves to a potential path further down the path list.
…tion directory does not exist (#4483) Summary: A recent change to take precedence of NODE_PATH for module resolution (#4453) made this issue more likely to occur since NODE_PATH could contain non-existent directories. While this could have occurred prior to the change, it was less likely since it is more common that modules are in local `node_modules`. Either way, non-existent directories should be treated the same way as non-existent files during module resolution. The equivalent case for `statSync` returning `ENOENT` for files is `ENOTDIR` for directories. We may want to add `ENOTDIR` to `isFile` as well. Test Plan: 1. `yarn test` 2. Link cli into another project, set NODE_PATH to non-existent directories, no longer see cryptic `Cannot find module` error. Instead, it now resolves to a potential path further down the path list.
…tion directory does not exist (jestjs#4483) Summary: A recent change to take precedence of NODE_PATH for module resolution (jestjs#4453) made this issue more likely to occur since NODE_PATH could contain non-existent directories. While this could have occurred prior to the change, it was less likely since it is more common that modules are in local `node_modules`. Either way, non-existent directories should be treated the same way as non-existent files during module resolution. The equivalent case for `statSync` returning `ENOENT` for files is `ENOTDIR` for directories. We may want to add `ENOTDIR` to `isFile` as well. Test Plan: 1. `yarn test` 2. Link cli into another project, set NODE_PATH to non-existent directories, no longer see cryptic `Cannot find module` error. Instead, it now resolves to a potential path further down the path list.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This aligns Jest with the behaviour of Node where it takes precedence of
NODE_PATH
over resolving modules relative tonode_modules
.Test plan
yolo