oxc-project/oxc · error · OxcDiagnostic
`{fn_name}` cannot be called as a constructor.
Error message
`{fn_name}` cannot be called as a constructor. What it means
Lint diagnostic from eslint/no-new-native-nonconstructor: new was used on a builtin that is not a constructor (e.g. new Symbol() or new BigInt()). These throw a TypeError at runtime since the spec defines them as non-constructable functions.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_new_native_nonconstructor.rs:9
use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};
fn no_new_native_nonconstructor_diagnostic(fn_name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("`{fn_name}` cannot be called as a constructor."))
.with_help(format!("Remove the `new` operator to call `{fn_name}` as a function."))
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoNewNativeNonconstructor;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow `new` operators with global non-constructor functions (`Symbol`, `BigInt`).
///
/// This rule can be disabled for TypeScript code, as the TypeScript compiler
/// enforces this check.
///
/// ### Why is this bad?
///
/// Both `new Symbol` and `new BigInt` throw a type error because they areView on GitHub (pinned to e1e7af627c)
Solutions
- Remove the new operator and call the builtin as a function, e.g. Symbol('x')
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/eslint/no_new_native_nonconstructor.rs:9 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/c4d2d2b60557fa88.
Report an issue: GitHub.