lib: fix TypeScript support check in jitless mode

WebAssembly is disabled when Node.js is run with --jitless. The
internal TypeScript stripper relies on WebAssembly, and previously
failed obscurely with a ReferenceError in this mode.

This commit adds an explicit check for WebAssembly support when
loading the TypeScript parser. If WebAssembly is unavailable,
it now throws a descriptive ERR_WEBASSEMBLY_NOT_SUPPORTED error.

Fixes: https://github.com/nodejs/node/issues/61353
PR-URL: https://github.com/nodejs/node/pull/61382
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
sangwook authored and Node.js GitHub Bot committed 2026-01-17 21:00:38 +00:00
1 parent 79ddd1ba10
commit 04c8828863
4 files changed
+26

No files matched your search

+8
View File
@@ -3350,6 +3350,14 @@ The WASI instance has already started.
The WASI instance has not been started.
<a id="ERR_WEBASSEMBLY_NOT_SUPPORTED"></a>
### `ERR_WEBASSEMBLY_NOT_SUPPORTED`
A feature requiring WebAssembly was used, but WebAssembly is not supported or
has been disabled in the current environment (for example, when running with
`--jitless`). The error message specifies which feature requires WebAssembly.
<a id="ERR_WEBASSEMBLY_RESPONSE"></a>
### `ERR_WEBASSEMBLY_RESPONSE`
+3
View File
@@ -1905,6 +1905,9 @@ E('ERR_VM_MODULE_NOT_MODULE',
'Provided module is not an instance of Module', Error);
E('ERR_VM_MODULE_STATUS', 'Module status %s', Error);
E('ERR_WASI_ALREADY_STARTED', 'WASI instance has already started', Error);
E('ERR_WEBASSEMBLY_NOT_SUPPORTED',
'WebAssembly is not supported in this environment, but is required for %s',
Error);
E('ERR_WEBASSEMBLY_RESPONSE', 'WebAssembly response %s', TypeError);
E('ERR_WORKER_INIT_FAILED', 'Worker initialization failure: %s', Error);
E('ERR_WORKER_INVALID_EXEC_ARGV', (errors, msg = 'invalid execArgv flags') =>
+4
View File
@@ -46,6 +46,7 @@ const {
SymbolPrototypeGetDescription,
SymbolReplace,
SymbolSplit,
globalThis,
} = primordials;
const {
@@ -53,6 +54,7 @@ const {
ERR_NO_CRYPTO,
ERR_NO_TYPESCRIPT,
ERR_UNKNOWN_SIGNAL,
ERR_WEBASSEMBLY_NOT_SUPPORTED,
},
isErrorStackTraceLimitWritable,
overrideStackTrace,
@@ -244,6 +246,8 @@ function assertCrypto() {
function assertTypeScript() {
if (noTypeScript)
throw new ERR_NO_TYPESCRIPT();
if (globalThis.WebAssembly === undefined)
throw new ERR_WEBASSEMBLY_NOT_SUPPORTED('TypeScript');
}
/**
+11
View File
@@ -342,3 +342,14 @@ test('check transform types warning', async () => {
assert.match(result.stdout, /Hello, TypeScript!/);
assert.strictEqual(result.code, 0);
});
test('expect error when executing a TypeScript file with --jitless', async () => {
const result = await spawnPromisified(process.execPath, [
'--jitless',
fixtures.path('typescript/ts/test-typescript.ts'),
]);
assert.match(result.stderr, /ERR_WEBASSEMBLY_NOT_SUPPORTED/);
assert.match(result.stderr, /WebAssembly is not supported in this environment, but is required for TypeScript/);
assert.strictEqual(result.code, 1);
});