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

[jest-resolve] Prevent default resolver failure when potential resolution directory does not exist #4483

Merged
merged 1 commit into from
Sep 15, 2017

Conversation

wschurman
Copy link
Contributor

@wschurman wschurman commented Sep 14, 2017

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, export NODE_PATH environment variable as a non-existent directory, no longer see cryptic Cannot find module error. 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.findNodeModule callsites. 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.

…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 cpojer merged commit 3aebe4f into jestjs:master Sep 15, 2017
@cpojer
Copy link
Member

cpojer commented Sep 15, 2017

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

3 participants