{"record":{"id":"7155141fbb11f39b","repo":"oxc-project/oxc","slug":"require-statement-not-part-of-import-statement","errorCode":null,"errorMessage":"Require statement not part of import statement.","messagePattern":"Require statement not part of import statement\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/typescript/no_var_requires.rs","lineNumber":9,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, ast_util::is_global_require_call, context::LintContext, rule::Rule};\n\nfn no_var_requires_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Require statement not part of import statement.\")\n        .with_help(\"Use ES module imports or `import = require` instead.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoVarRequires;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow `require` statements except in import statements.\n    ///\n    /// **NOTE**: This rule is intentionally missing the `allow` option from the original typescript-eslint rule.\n    /// This rule is deprecated in the upstream plugin and the `typescript/no-require-imports` rule should be\n    /// used instead.\n    ///\n    /// ### Why is this bad?\n    ///","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_var_requires.rs#L1-L27","documentation":"Raised by typescript/no_var_requires when a `require(...)` call (a global CommonJS require, per is_global_require_call) is assigned to a variable via `var`/`let`/`const` or otherwise used outside an import statement. At the throw site the code mixes CommonJS require into a TS module where TypeScript conventions (and `import = require` for types) apply; plain require bypasses type resolution and module semantics. no_var_requires_diagnostic fires from run() for each standalone require-call assignment.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/typescript/no_var_requires.rs:9 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use `import fs from \"fs\"` instead.","For types-only imports needing the pattern, use `import x = require(\"...\")`."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}