ERR_WASI_ALREADY_STARTED
Node.jsERRORCriticalWASIHIGH confidence

WASI instance has already been started

Production Risk

Low — WASI usage is specialised; create fresh instances for each execution.

What this means

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.

Why it happens
  1. 1Calling wasi.start() more than once on the same WASI instance
  2. 2Calling wasi.initialize() after wasi.start() on the same instance
How to reproduce

Triggered when start() or initialize() is called on an already-started WASI instance.

trigger — this will error
trigger — this will 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

expected 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

Create a new WASI instance for each module execution
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.

Code examples
Triggerjs
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_STARTED
Handle in try/catchjs
try {
  // 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
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_wasi_already_started(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Reuse WASI instances across multiple WebAssembly executions

WASI instances are stateful and can only be started once per instantiation.

Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors