Commit a16910e
authored
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`.1 parent 5b21175 commit a16910e
2 files changed
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1375 | 1375 | | |
1376 | 1376 | | |
1377 | 1377 | | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
1378 | 1397 | | |
1379 | 1398 | | |
1380 | 1399 | | |
| |||
1675 | 1694 | | |
1676 | 1695 | | |
1677 | 1696 | | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
1678 | 1700 | | |
1679 | 1701 | | |
1680 | 1702 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3111 | 3111 | | |
3112 | 3112 | | |
3113 | 3113 | | |
| 3114 | + | |
3114 | 3115 | | |
3115 | 3116 | | |
3116 | 3117 | | |
| |||
0 commit comments