WASI instance has already been started
Production Risk
Low — WASI usage is specialised; create fresh instances for each execution.
Thrown when wasi.start() or wasi.initialize() is called on a WASI instance that has already been started or initialised. A WASI instance can only be started once; calling start() again on the same instance is not permitted.
- 1Calling wasi.start() more than once on the same WASI instance
- 2Calling wasi.initialize() after wasi.start() on the same instance
Triggered when start() or initialize() is called on an already-started WASI instance.
const { WASI } = require('wasi');
const wasi = new WASI();
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
// ... load and instantiate WebAssembly module
wasi.start(instance);
wasi.start(instance); // throws — already startedexpected output
Error [ERR_WASI_ALREADY_STARTED]: WASI instance has already started
Fix
Create a new WASI instance for each module execution
WHEN When running a WASM module multiple times
function runWasm(wasmBuffer) {
const wasi = new WASI({ args: process.argv, env: process.env });
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
const { instance } = WebAssembly.instantiateSync(wasmBuffer, importObject);
wasi.start(instance);
}Why this works
Each new WASI instance starts fresh; creating one per execution avoids the already-started error.
const { WASI } = require('wasi');
const wasi = new WASI();
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
// ... load and instantiate WebAssembly module
wasi.start(instance);
wasi.start(instance); // throws — already started // this triggers ERR_WASI_ALREADY_STARTEDtry {
// operation that may throw ERR_WASI_ALREADY_STARTED
riskyOperation()
} catch (err) {
if (err.code === 'ERR_WASI_ALREADY_STARTED') {
console.error('ERR_WASI_ALREADY_STARTED:', err.message)
} else {
throw err
}
}// Validate inputs before calling the operation
function safe_err_wasi_already_started(...args) {
// validate args here
return performOperation(...args)
}✕ Reuse WASI instances across multiple WebAssembly executions
WASI instances are stateful and can only be started once per instantiation.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev