denoland/deno · error · ERR_INVALID_ARG_VALUE
ERR_INVALID_ARG_VALUE
ERR_INVALID_ARG_VALUE
Error message
The property 'options.version' must be "preview1" or "unstable". Received ${options.version} What it means
Thrown by the WASI constructor when options.version is present but is neither "preview1" nor "unstable". These two strings select the WASI snapshot (wasi_snapshot_preview1 vs wasi_unstable) that determines which import object the instance exposes. Any other value, including newer names like "preview2", is rejected.
Source
Thrown at ext/node/polyfills/wasi.ts:157
#ctx;
#version: string;
#started = false;
#returnOnExit: boolean;
#wasiImport;
constructor(options?: WasiOptions) {
emitExperimentalWarning();
if (options === undefined) {
throw new ERR_INVALID_ARG_TYPE("options.version", "string", undefined);
}
validateObject(options, "options");
if (options.version === undefined) {
throw new ERR_INVALID_ARG_TYPE("options.version", "string", undefined);
}
validateString(options.version, "options.version");
if (options.version !== "preview1" && options.version !== "unstable") {
throw new ERR_INVALID_ARG_VALUE(
"options.version",
options.version,
'must be "preview1" or "unstable"',
);
}
const argsValue = options.args ?? [];
if (options.args !== undefined) {
validateArray(options.args, "options.args");
}
const args = ArrayPrototypeMap(argsValue, (arg) => String(arg));
const envObj = options.env ?? {};
if (options.env !== undefined) {
validateObject(options.env, "options.env");
}
const envPairs: [string, string][] = [];
for (const entry of new SafeArrayIterator(ObjectEntries(envObj))) {View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Set `version: "preview1"` — this is the value virtually all command-line wasm modules built with wasi-sdk/clang --target=wasi32-wasi use.
- If you need reactorthreaded modules documented as 'unstable', use `version: "unstable"`.
- Do not feed preview2 component strings into this API; use a preview2-capable runtime or compile the module with the preview1 adapter instead.
Example fix
// before
const wasi = new WASI({ version: "preview2" });
// after
const wasi = new WASI({ version: "preview1" }); Defensive patterns
Strategy: validation
Validate before calling
const VALID_WASI_VERSIONS = new Set(['preview1', 'unstable']);
if (!VALID_WASI_VERSIONS.has(userVersion)) {
throw new Error(`Unsupported WASI version ${userVersion}; use "preview1"`);
} Type guard
function isWasiVersion(v: unknown): v is 'preview1' | 'unstable' {
return v === 'preview1' || v === 'unstable';
} Prevention
- Treat the version as a closed union type 'preview1' | 'unstable', never a free-form string.
- Remember node:wasi has no preview2 support; preview2 needs a different runtime.
When it happens
Trigger: `new WASI({ version: "preview2" })` (WASI preview2 is a different API and not accepted here), `version: "latest"`, a typo like "preivew1", or a version string read from an env var / package.json that uses different naming.
Common situations: Assuming the Node WASI API supports WASI preview2 (it does not — preview2 is component-model based and served by separate runtimes); upgrading a toolchain that emits a different version string; sharing one config between a Wasmtime embedder and the Node API.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ERR_INVALID_ARG_TYPE
- ERR_WASI_NOT_STARTED
- ERR_WASI_ALREADY_STARTED
- ERR_TLS_ALPN_CALLBACK_WITH_PROTOCOLS
- UVWASI_ENOENT
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/22ce059072d674ac.
Report an issue: GitHub.