fix(ext/node): fix Module._resolveLookupPaths and require.resolve compat#33261
Open
bartlomieju wants to merge 1 commit intomainfrom
Open
fix(ext/node): fix Module._resolveLookupPaths and require.resolve compat#33261bartlomieju wants to merge 1 commit intomainfrom
bartlomieju wants to merge 1 commit intomainfrom
Conversation
Fixes several Node.js compatibility issues in the CJS module resolver:
- `Module._resolveLookupPaths` now returns `null` for built-in modules,
matching Node.js behavior. Libraries like requizzle (used by jsdoc)
rely on this to detect native modules.
- `require.resolve` and `require.resolve.paths` now validate argument
types, throwing `ERR_INVALID_ARG_TYPE` for non-string arguments.
- `require.resolve` with `options.paths` now validates path entries are
strings and resolves relative paths against CWD.
- `require.resolve('node:unknown')` now throws `MODULE_NOT_FOUND`
instead of silently returning the invalid specifier.
- Fix panic in `op_require_resolve_lookup_paths` when `parent_filename`
is empty (e.g. REPL or fakeParent contexts).
- Treat `"."` as a relative request in `op_require_is_request_relative`.
Closes #33258
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
miracatbot
approved these changes
Apr 13, 2026
miracatbot
left a comment
There was a problem hiding this comment.
Looks good to me.
The built-in handling now matches Node much better: _resolveLookupPaths() returns null for builtins, valid node: builtins resolve correctly, and unknown node: specifiers now fail with MODULE_NOT_FOUND instead of being treated as valid.
The additional request/options validation and the empty parent.filename handling also look like the right fixes for the compat cases covered by the newly enabled tests.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Module._resolveLookupPathsnow returnsnullfor built-in modules, matching Node.js behaviorrequire.resolve/require.resolve.pathsvalidate argument types (ERR_INVALID_ARG_TYPE)require.resolvewithoptions.pathsvalidates path entries and resolves relative paths against CWDrequire.resolve('node:unknown')throwsMODULE_NOT_FOUNDinstead of silently returningop_require_resolve_lookup_pathswhenparent_filenameis empty"."as a relative request inop_require_is_request_relativetest-require-resolve,test-require-resolve-invalid-paths,test-require-resolve-opts-paths-relativeCloses #33258
Test plan
./x test-compat test-require-resolve)tools/format.jsandtools/lint.jsclean🤖 Generated with Claude Code