|
1 | 1 | # enhanced-resolve |
2 | 2 |
|
| 3 | +## 5.20.2 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- fix: prevent fallback to parent node_modules when exports field target file is not found (by [@xiaoxiaojx](https://github.com/xiaoxiaojx) in [#495](https://github.com/webpack/enhanced-resolve/pull/495)) |
| 8 | + |
| 9 | + When a package has an `exports` field that maps a request to a target file, |
| 10 | + but that target file does not exist on disk, enhanced-resolve was incorrectly |
| 11 | + falling back to search parent `node_modules` directories. This violated the |
| 12 | + Node.js ESM resolution spec, which requires resolution to fail with an error |
| 13 | + rather than continue searching up the directory tree. |
| 14 | + |
| 15 | + This manifested in monorepos where the same package exists at multiple levels |
| 16 | + (e.g. `workspace/node_modules/pkg` and `root/node_modules/pkg`): if the |
| 17 | + workspace version's exports-mapped target was missing, the resolver would |
| 18 | + silently resolve to the root version instead. |
| 19 | + |
| 20 | + Root cause: `ExportsFieldPlugin` was returning `null` on failure, which |
| 21 | + `Resolver.doResolve` converted to `undefined`, causing |
| 22 | + `ModulesInHierarchicalDirectoriesPlugin` to treat the lookup as "not found, |
| 23 | + try next directory" rather than a hard stop. |
| 24 | + |
| 25 | + Fix: when the `exports` field is present and a match is found but no valid |
| 26 | + target file can be resolved, return an explicit error to stop directory |
| 27 | + traversal. Closes #399. |
| 28 | + |
| 29 | +- Imports field spec deviation: non-relative targets (e.g. `"#a": "#b"`) (by [@xiaoxiaojx](https://github.com/xiaoxiaojx) in [#503](https://github.com/webpack/enhanced-resolve/pull/503)) |
| 30 | + no longer re-enter imports resolution, aligning with the Node.js ESM spec |
| 31 | + where `PACKAGE_IMPORTS_RESOLVE` does not recursively resolve `#` specifiers. |
| 32 | + |
| 33 | + Previously `{ "#a": "#b", "#b": "./the.js" }` would chain-resolve `#a` to |
| 34 | + `./the.js`; now it correctly fails, matching Node.js behavior. |
| 35 | + |
| 36 | +- When `tsconfig: true` is used (default config file) and no `tsconfig.json` (by [@xiaoxiaojx](https://github.com/xiaoxiaojx) in [#502](https://github.com/webpack/enhanced-resolve/pull/502)) |
| 37 | + exists, `TsconfigPathsPlugin` threw a file-not-found error that caused |
| 38 | + the entire resolve to fail — even for relative imports that don't need |
| 39 | + tsconfig path mappings. |
| 40 | + |
| 41 | + Fix: when using the default config file and `tsconfig.json` is not found, |
| 42 | + the plugin now returns `null` and lets resolution continue normally. |
| 43 | + When the user provides an explicit path (string), a missing file still |
| 44 | + throws an error as expected. |
| 45 | + |
3 | 46 | ## 5.20.1 |
4 | 47 |
|
5 | 48 | ### Patch Changes |
|
0 commit comments