deno
a16910ee - fix(ext/node): throw ERR_UNKNOWN_BUILTIN_MODULE for unknown node: builtins (#34766)

Commit
62 days ago
fix(ext/node): throw ERR_UNKNOWN_BUILTIN_MODULE for unknown node: builtins (#34766) Node's CommonJS loader throws `ERR_UNKNOWN_BUILTIN_MODULE` (with message `No such built-in module: <id>`) when `require()` is given a `node:`-prefixed specifier that is not a public builtin. Two cases were handled incorrectly: 1. `require("node:unknown")` threw a generic `MODULE_NOT_FOUND` `Error` instead of `ERR_UNKNOWN_BUILTIN_MODULE`. 2. `require("node:internal/...")` resolved to Deno's internal polyfill modules. Node only exposes `internal/*` builtins under `--expose-internals`, so from userland these should be treated as unknown. This matches the existing `isBuiltin()` check and the public `builtinModules` list, both of which already exclude `internal/*`. This changes the `node:`-scheme branch of `Module._resolveFilename` to skip `internal/*` ids and to throw `internalErrors.ERR_UNKNOWN_BUILTIN_MODULE`. Bare (non-`node:`-prefixed) `require("internal/...")` is intentionally left unchanged. Enables the upstream test `parallel/test-require-node-prefix.js`.
Author
Parents
Loading