{"record":{"id":"ec0edf231b32b1ea","repo":"oxc-project/oxc","slug":"a-require-style-import-is-forbidden","errorCode":null,"errorMessage":"A `require()` style import is forbidden.","messagePattern":"A `require\\(\\)` style import is forbidden\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/no_unassigned_import.rs","lineNumber":121,"sourceCode":"                        \"Imported module should be assigned\",\n                    ));\n                }\n            }\n            AstKind::ExpressionStatement(statement) => {\n                let Expression::CallExpression(call_expr) = &statement.expression else {\n                    return;\n                };\n                if !call_expr.is_require_call() {\n                    return;\n                }\n                let first_arg = &call_expr.arguments[0];\n                let Argument::StringLiteral(source_str) = first_arg else {\n                    return;\n                };\n                if !self.is_match_allow_globs(source_str.value.as_str()) {\n                    ctx.diagnostic(no_unassigned_import_diagnostic(\n                        call_expr.span,\n                        \"A `require()` style import is forbidden.\",\n                    ));\n                }\n            }\n            _ => {}\n        }\n    }\n}\n\nimpl NoUnassignedImportConfig {\n    fn is_match_allow_globs(&self, source: &str) -> bool {\n        self.globs.iter().any(|glob| fast_glob::glob_match(glob.as_str(), source))\n    }\n}\n\n#[test]\nfn test() {\n    use crate::tester::Tester;\n    use serde_json::json;","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/no_unassigned_import.rs#L103-L139","documentation":"This is the CommonJS variant of oxlint's 'import/no-unassigned-imports' diagnostic. It fires when a call expression statement that is a require() call takes a string literal argument and its result is discarded, e.g. require('should'). The message exists because a require whose return value is unused signals either dead code or a hidden side-effect dependency, which hurts testability and bundle trimming.","triggerScenarios":"Run oxlint with import/no-unassigned-imports enabled on code containing an ExpressionStatement whose expression is a require() call with a string literal first argument that does not match any allow glob. The diagnostic is attached to the call expression's span.","commonSituations":"Classic Node scripts and migration-era codebases contain require('./env'), require('dotenv/config'), or require('should') purely for side effects. Enabling this rule without an allow list flags all of them at once, which looks like a regression but is the rule working as designed.","solutions":["Remove the require if the module's side effects are not needed.","Capture the result if you actually use it: const should = require('should').","Add the intentional side-effect modules to the allow globs: \"import/no-unassigned-imports\": [\"error\", { \"allow\": [\"dotenv/config\", \"**/*.css\"] }].","Suppress the single occurrence with an // oxlint-disable-next-line import/no-unassigned-imports comment if the pattern is deliberate."],"exampleFix":"// before\nrequire('dotenv/config');\nrequire('./polyfills');\n\n// after\n// .oxlintrc.json: \"import/no-unassigned-imports\": [\"error\", { \"allow\": [\"dotenv/config\"] }]\nrequire('dotenv/config');\nconst polyfills = require('./polyfills');","handlingStrategy":"validation","validationCode":"# list bare require() statements before enabling the rule\nrg -n \"^\\s*require\\s*\\(\\s*['\\\"][^'\\\"]+['\\\"]\\s*\\)\\s*;\" src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert side-effect requires to explicit bindings during CommonJS modernization.","Record intentional side-effect modules (dotenv/config, instrumentation) in the rule's allow list.","Review new bare require() calls in code review since they bypass tree-shaking."],"tags":["lint","require","commonjs","side-effects","oxlint"],"backgroundTag":"side-effect-import","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}