diff --git a/doc/api/errors.md b/doc/api/errors.md index a63fb28ab8933d..b55f659c39ed94 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -3350,6 +3350,14 @@ The WASI instance has already started. The WASI instance has not been started. + + +### `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`). + ### `ERR_WEBASSEMBLY_RESPONSE` diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 5fa4437b09e556..7c4728627731fe 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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') => diff --git a/lib/internal/util.js b/lib/internal/util.js index 9739422d08284a..28bb83e558c426 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -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'); } /** diff --git a/test/es-module/test-typescript.mjs b/test/es-module/test-typescript.mjs index df25f60defd35b..2e98bc3f289d1e 100644 --- a/test/es-module/test-typescript.mjs +++ b/test/es-module/test-typescript.mjs @@ -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); +});