ERR_INVALID_REPL_EVAL_CONFIG
Node.jsERRORCriticalChild ProcessHIGH confidence

REPL eval and useGlobal options are mutually exclusive

Production Risk

Low — typically only in developer tooling or REPL-based applications.

What this means

Thrown when repl.start() is configured with both a custom eval function and useGlobal: true simultaneously. These options are mutually exclusive: a custom eval function defines how code is evaluated, and useGlobal specifies that the global context should be used; combining them is contradictory.

Why it happens
  1. 1Passing both eval and useGlobal: true to repl.start()
  2. 2Misunderstanding that useGlobal only applies to the default evaluator
How to reproduce

Triggered when repl.start() validates its options and finds both eval and useGlobal: true.

trigger — this will error
trigger — this will error
const repl = require('repl');
repl.start({
  eval: (cmd, ctx, file, cb) => cb(null, eval(cmd)),
  useGlobal: true, // mutually exclusive with custom eval
});

expected output

Error [ERR_INVALID_REPL_EVAL_CONFIG]: Cannot specify both "useGlobal" and "eval" for REPL

Fix 1

Remove useGlobal when using a custom eval function

WHEN When implementing a custom evaluator

Remove useGlobal when using a custom eval function
const repl = require('repl');
repl.start({
  eval: (cmd, context, filename, callback) => {
    let result;
    try { result = eval(cmd); } catch (e) { return callback(e); }
    callback(null, result);
  },
  // no useGlobal
});

Why this works

Omitting useGlobal resolves the mutual exclusion; the custom eval controls context usage.

Fix 2

Remove the custom eval and use useGlobal instead

WHEN When you only need global context sharing

Remove the custom eval and use useGlobal instead
const repl = require('repl');
repl.start({ useGlobal: true }); // uses default evaluator with global context

Why this works

useGlobal: true with the default evaluator shares the global context without a custom eval.

Code examples
Triggerjs
const repl = require('repl');
repl.start({
  eval: (cmd, ctx, file, cb) => cb(null, eval(cmd)),
  useGlobal: true, // mutually exclusive with custom eval
});  // this triggers ERR_INVALID_REPL_EVAL_CONFIG
Handle in try/catchjs
try {
  // operation that may throw ERR_INVALID_REPL_EVAL_CONFIG
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_INVALID_REPL_EVAL_CONFIG') {
    console.error('ERR_INVALID_REPL_EVAL_CONFIG:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_invalid_repl_eval_config(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Combine custom eval and useGlobal: true

They are mutually exclusive; one defines the evaluator, the other controls the default evaluator's context.

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