ERR_WORKER_INVALID_EXEC_ARGV
Node.jsERRORNotableWorkerHIGH confidence

Invalid execArgv passed to Worker constructor

Production Risk

Low — caught at startup; review which flags are valid in worker context.

What this means

Thrown when the execArgv option passed to new Worker() contains flags that are not allowed in a worker context, or flags that require a value but are missing one. Some Node.js CLI flags cannot be used inside worker threads.

Why it happens
  1. 1Passing --prof or --prof-process in worker execArgv (not allowed in workers)
  2. 2Passing an incomplete flag that requires an argument
  3. 3Including flags that require process-level changes not applicable to workers
How to reproduce

Triggered when the Worker constructor validates the execArgv option.

trigger — this will error
trigger — this will error
const { Worker } = require('worker_threads');
new Worker('./w.js', {
  execArgv: ['--prof'], // profiling flags not allowed in workers
});

expected output

Error [ERR_WORKER_INVALID_EXEC_ARGV]: Initiated Worker with invalid execArgv flags: --prof

Fix 1

Use only allowed flags in worker execArgv

WHEN When customising the worker Node.js runtime

Use only allowed flags in worker execArgv
const w = new Worker('./w.js', {
  execArgv: ['--max-old-space-size=512', '--harmony'],
});

Why this works

Only standard V8/Node.js flags that are valid in a forked context are permitted in worker execArgv.

Fix 2

Profile at the main process level instead

WHEN When you need CPU profiling

Profile at the main process level instead
// Run the main process with --prof and let workers be created normally
// node --prof main.js

Why this works

Process-level profiling flags apply to the entire V8 instance; workers share the profiler.

Code examples
Triggerjs
const { Worker } = require('worker_threads');
new Worker('./w.js', {
  execArgv: ['--prof'], // profiling flags not allowed in workers
});  // this triggers ERR_WORKER_INVALID_EXEC_ARGV
Handle in try/catchjs
try {
  // operation that may throw ERR_WORKER_INVALID_EXEC_ARGV
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_WORKER_INVALID_EXEC_ARGV') {
    console.error('ERR_WORKER_INVALID_EXEC_ARGV:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_worker_invalid_exec_argv(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Copy all main process execArgv into worker execArgv

Some flags are only valid at process start and cannot be applied to individual worker threads.

Same error in other languages
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