JavaScript Error

EvalError

EvalError historically indicated errors related to the eval() function. While modern JavaScript engines no longer throw EvalError, it still exists in the language for backward compatibility. The constructor can be used to create custom instances.

Common causes

  • Legacy code using eval() in restricted environments
  • Custom error handling that throws EvalError instances
  • Using eval() in strict mode with certain constraints
  • Older JavaScript engines that still throw this error
  • Libraries that throw EvalError for eval-related failures

How to fix it

  • Avoid using eval() entirely — use safer alternatives like JSON.parse()
  • Use Function constructor if dynamic code execution is needed
  • Replace eval with structured data parsing
  • Use Content Security Policy (CSP) to prevent eval usage
  • Handle EvalError alongside other error types in catch blocks

Example

EvalError example
// EvalError is rarely thrown by modern engines
// but can be created manually:
try {
  throw new EvalError("eval not allowed");
} catch (e) {
  console.log(e instanceof EvalError);  // true
  console.log(e.message);  // "eval not allowed"
}

// Instead of eval, use safer alternatives:
// Bad: eval('{ "name": "Alice" }')
const data = JSON.parse('{ "name": "Alice" }');

// Bad: eval("2 + 2")
const fn = new Function("return 2 + 2");
fn();  // 4

Track EvalError with Checkend

Checkend automatically captures EvalError errors in your JavaScript application with full context:

  • Complete stack trace with source maps
  • Browser and environment context
  • Automatic grouping of similar errors
  • Instant notifications when errors occur

Stop debugging in production

Get full error context and fix issues faster with self-hosted error tracking.