unambiguous
Forbid potentially ambiguous parse goal (script vs. module)
💼 This rule is enabled in the following configs: recommended, typescript.
Rule Details
Tools that follow the Unambiguous JavaScript Grammar decide between script and module from the syntax alone. A file with no import or export parses as a script too, so a tool may load your module in the wrong mode. This rule reports a module file with code but no module syntax.
Module syntax is: an import declaration (also type-only and side-effect), any export (also export {} and TS export =), TS import x = require('m') (TypeScript treats the file as a module), and import.meta (a syntax error in a script). A dynamic import() is legal in a script, so it does not disambiguate.
Not reported: an empty file, a file with a 'use strict' directive (its author stated a parse mode), and a file the config parses as a script or CommonJS, or a .cjs / .cts file (CommonJS by its extension). oxlint infers the parse goal from the content, so there a file counts as not-a-module only by a CommonJS sourceType or its extension.
❌ Incorrect
const a = 1;
console.log(a);
const lazy = () => import('./a');✅ Correct
import a from './a';
console.log(a);
console.log(import.meta.url);
const b = 1;
export {};Options
[]No options.
When Not To Use It
When every consumer of your files is told the parse mode explicitly ("type": "module", .mjs, bundler config).
Use this rule
npm install -D oxlint-plugin-import-next{ "jsPlugins": ["oxlint-plugin-import-next"], "rules": { "import-next/unambiguous": "error" }}import { defineConfig } from 'vite-plus';export default defineConfig({ lint: { jsPlugins: ['oxlint-plugin-import-next'], rules: { 'import-next/unambiguous': 'error', }, },});oxlint-plugin-import-next re-exports eslint-plugin-import-next/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.
Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.