REPL eval and useGlobal options are mutually exclusive
Production Risk
Low — typically only in developer tooling or REPL-based applications.
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.
- 1Passing both eval and useGlobal: true to repl.start()
- 2Misunderstanding that useGlobal only applies to the default evaluator
Triggered when repl.start() validates its options and finds both eval and useGlobal: true.
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
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
const repl = require('repl');
repl.start({ useGlobal: true }); // uses default evaluator with global contextWhy this works
useGlobal: true with the default evaluator shares the global context without a custom eval.
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_CONFIGtry {
// 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
}
}// Validate inputs before calling the operation
function safe_err_invalid_repl_eval_config(...args) {
// validate args here
return performOperation(...args)
}✕ Combine custom eval and useGlobal: true
They are mutually exclusive; one defines the evaluator, the other controls the default evaluator's context.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev