-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Description
Executing
const neverLinked = new vm.Module('import "nonexistent";');
// Note: `await` intentionally omitted as the returned promise will never resolve.
neverLinked.link(() => new Promise(() => {}));
const main = new vm.Module('import "neverLinked";');
await main.link(() => neverLinked);
main.instantiate();
with --experimental-vm-modules
throws
internal/vm/Module.js:170
wrap.instantiate();
^
Error: linking error, dependency promises must be resolved on instantiate
at Module.instantiate (internal/vm/Module.js:170:10)
which does not have the error code that is present on all other errors thrown by instantiate()
. In comparison,
new vm.Module('').instantiate();
throws an error with a proper error code:
Error [ERR_VM_MODULE_NOT_LINKED]: Module must be linked before it can be instantiated
The thrown error comes from
node/lib/internal/vm/Module.js
Line 170 in 9974d6a
wrap.instantiate(); |
which due to restrictions on how V8's C++ API operates makes it inconvenient to add the error code. The way to fix this would be to wrap a try
-catch
block around
node/lib/internal/vm/Module.js
Line 170 in 9974d6a
wrap.instantiate(); |
to throw a proper errors.Error
. The error message can be hard-coded as Linked dependencies must all be linked before instantiation
, since this should be the only possible error thrown from this line.
See also #18106.