Skip to content

Commit

Permalink
[jest-resolve] Prevent default resolver failure when potential resolu…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
wschurman committed Sep 14, 2017
1 parent 13e4ba2 commit 86ebd2e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/jest-resolve/src/default_resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function isDirectory(dir: Path): boolean {
const stat = fs.statSync(dir);
result = stat.isDirectory();
} catch (e) {
if (!(e && e.code === 'ENOENT')) {
if (!(e && (e.code === 'ENOENT' || e.code === 'ENOTDIR'))) {
throw e;
}
result = false;
Expand Down

0 comments on commit 86ebd2e

Please sign in to comment.