sea: allow requiring core modules with the "node:" prefix
Previously, the require()
function exposed to the embedded SEA code was calling the internal require()
function if the module name belonged to the list of public core modules but the internal require()
function does not support loading modules with the "node:" prefix, so this change forwards the calls to another require()
function that supports this.
Fixes: https://github.com/nodejs/single-executable/issues/69
bootstrap: fix bug in the snapshot require function and share the code with the SEA require
Previously, requiring node:test
while building a snapshot
was failing with a Error: Cannot find module 'node:test'.
error, so
this change fixes that and uses the same code path for normalizing ids
for both the snapshot require function as well as the SEA require
function.
Previously:
$ node --snapshot-blob snapshot.blob --build-snapshot <(echo "require('node:test')")
node:internal/main/mksnapshot:105
throw err;
^
Error: Cannot find module 'node:test'.
at requireForUserSnapshot (node:internal/main/mksnapshot:101:17)
at /dev/fd/13:1:1
at main (node:internal/main/mksnapshot:168:5)
at node:internal/main/mksnapshot:185:1
$ node --snapshot-blob snapshot.blob --build-snapshot <(echo "require('test')")
(node:5389) Warning: built-in module test is not yet supported in user snapshots
(Use `node --trace-warnings ...` to show where the warning was created)
Unknown external reference 0x102d226e0.
<unresolved>
[1] 5389 trace trap node --snapshot-blob snapshot.blob --build-snapshot <(echo "require('test')")
Now:
$ ./node --snapshot-blob snapshot.blob --build-snapshot <(echo "require('node:test')")
(node:5394) Warning: built-in module node:test is not yet supported in user snapshots
(Use `node --trace-warnings ...` to show where the warning was created)
Unknown external reference 0x105cb25e0.
<unresolved>
[1] 5394 trace trap ./node --snapshot-blob snapshot.blob --build-snapshot
$ ./node --snapshot-blob snapshot.blob --build-snapshot <(echo "require('test')")
node:internal/main/mksnapshot:106
throw err;
^
Error: Cannot find module 'test'.
at requireForUserSnapshot (node:internal/main/mksnapshot:102:17)
at /dev/fd/13:1:1
at main (node:internal/main/mksnapshot:169:5)
at node:internal/main/mksnapshot:186:1
Since the Unknown external reference
error, which happens now for
the node:test
module, was already present for the test
module,
it should be okay to fix in a separate PR.
More info about the crash in https://github.com/nodejs/node/issues/47832.
Refs: https://github.com/nodejs/node/pull/47779#discussion_r1181671294 Signed-off-by: Darshan Sen raisinten@gmail.com
cc @nodejs/single-executable