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

Take precedence of NODE_PATH when resolving node_modules directories #4453

Merged
merged 1 commit into from
Sep 8, 2017
Merged

Take precedence of NODE_PATH when resolving node_modules directories #4453

merged 1 commit into from
Sep 8, 2017

Conversation

sebmck
Copy link

@sebmck sebmck commented Sep 8, 2017

Summary

This aligns Jest with the behaviour of Node where it takes precedence of NODE_PATH over resolving modules relative to node_modules.

Test plan

yolo

@cpojer cpojer merged commit fab01c7 into jestjs:master Sep 8, 2017
@codecov-io
Copy link

Codecov Report

Merging #4453 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
packages/jest-resolve/src/node_modules_paths.js 5.88% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b484db...1814193. Read the comment docs.

@wschurman
Copy link
Contributor

wschurman commented Sep 14, 2017

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

Test suite failed to run

Cannot find module 'lodash/isPlainObject' from 'createStore.js'

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:192:17)
  at Object.<anonymous> (node_modules/redux/lib/createStore.js:7:22)

Edit: looking more at this, I think the correct solution is to throw a clearer error including the attempted module resolution path.

wschurman added a commit to wschurman/jest that referenced this pull request Sep 14, 2017
…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.
cpojer pushed a commit that referenced this pull request Sep 15, 2017
…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.
tabrindle pushed a commit to tabrindle/jest that referenced this pull request Oct 2, 2017
…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.
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants