[jest-resolve] Prevent default resolver failure when potential resolution directory does not exist#4483
Merged
Merged
Conversation
…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.
Member
|
Sure. A test would be nice. |
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.
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
statSyncreturningENOENTfor files isENOTDIRfor directories. We may want to addENOTDIRtoisFileas well.Test plan
yarn testCannot find moduleerror. Instead, it now resolves to a potential path further down the path list.Additional Context
One other potential fix would be to propagate these exceptions up to the
Resolver.findNodeModulecallsites. Currently, this method absorbs all exceptions though, and since it is used externally by jest-config, I figured keeping the existing non-throwing API was preferable.