{"record":{"id":"fb797f6605b283c3","repo":"oxc-project/oxc","slug":"this-module-could-be-mistakenly-parsed-as-script-i","errorCode":null,"errorMessage":"This module could be mistakenly parsed as script instead of module","messagePattern":"This module could be mistakenly parsed as script instead of module","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/unambiguous.rs","lineNumber":8,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{context::LintContext, rule::Rule};\n\nfn unambiguous_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"This module could be mistakenly parsed as script instead of module\")\n        .with_help(\"Add at least one import or export statement to unambiguously mark this file as a module\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct Unambiguous;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Warn if a `module` could be mistakenly parsed as a `script` instead of\n    /// as a pure [ES module](https://nodejs.org/api/esm.html#modules-ecmascript-modules).\n    ///\n    /// ### Why is this bad?\n    ///\n    /// For ESM-only environments, ambiguous files may lead to unexpected results and problems.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/unambiguous.rs#L1-L26","documentation":"This is oxlint's 'import/unambiguous' diagnostic. The rule runs only on files parsed as ES modules and reports those that contain no import or export statements at all. Such a file is syntactically valid as both a script and a module, so tools that must pick one (Node with/without \"type\": \"module\", bundlers, test runners) can guess wrong, changing semantics like strict mode and top-level this.","triggerScenarios":"Enable import/unambiguous and lint a file that is treated as a module (e.g. .mjs, or a .js file in a \"type\": \"module\" package) but contains zero import/export declarations. The diagnostic fires with the help 'Add at least one import or export statement'.","commonSituations":"Published npm packages that ship plain helper files hit this because consumers may load the file as CommonJS. Monorepos where some packages set \"type\": \"module\" and others do not also produce ambiguous files. CI lint gates then fail on otherwise-working utility modules.","solutions":["Add an explicit empty export at the end of the file: export {};","If the file genuinely imports or should import something, add the real import/export statements.","If the file is meant to be a script, move it out of module contexts (rename to .cjs or remove \"type\": \"module\" handling) so the rule does not apply.","Disable the rule for script-like directories via overrides in .oxlintrc.json."],"exampleFix":"// before (helpers.js in a \"type\": \"module\" package)\nexport {};\n// (file originally had no import/export at all)\n\n// after\nexport {}; // placed at the end of the file","handlingStrategy":"validation","validationCode":"// list module-context files lacking import/export (candidates for export {})\nconst { execSync } = require('node:child_process');\nconst files = execSync(\"rg -L --files-without-match '^(import|export)\\\\b' src/ --glob '*.mjs'\", { encoding: 'utf8' });\nconsole.log(files);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["End every module-context file with export {} if it has no other module syntax.","Set \"type\" in package.json deliberately and keep file extensions (.cjs/.mjs) consistent with it.","Run import/unambiguous in CI when publishing packages consumed by both CJS and ESM tools."],"tags":["lint","import","esm","module","commonjs","oxlint"],"backgroundTag":"ambiguous-module-script","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"}