Skip to main content
interlace
Plugin: import-nextRules

no-import-module-exports

Forbid import statements with CommonJS module.exports

💼 This rule is enabled in the following configs: recommended, typescript.

Rule Details

A file that runs import declarations and also exports through CommonJS mixes two module systems: bundlers treat it as an ES module, where module.exports does not exist, and the exports silently disappear. This rule reports the CommonJS exports of such a file. It needs both:

  • a value import ... from 'm'. A type-only import type is erased at compile time and mixes nothing; a dynamic import() is legal in CommonJS.
  • a use of the global module / exports: assigning module.exports (dotted or computed) or one of its properties, reading module.exports, or assigning a property of exports.

A module / exports bound in the file (a wrapper's parameters) is not the CommonJS global.

❌ Incorrect

import dep from './dep';
module.exports = { run: dep };

✅ Correct

import dep from './dep';
export const run = dep;

import type { Dep } from './dep';
module.exports = { run: (d: Dep) => d };

Options

[
  {
    "type": "object",
    "properties": {
      "exceptions": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    },
    "additionalProperties": false
  }
]
  • exceptions (default []): file globs (or path substrings) where mixing is accepted, e.g. ["**/scripts/**"]. A glob matches any run of whole path segments.

When Not To Use It

When a build step you control transpiles these files to CommonJS and the mix is intended.

Use this rule

npm install -D oxlint-plugin-import-next
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-import-next"],  "rules": {    "import-next/no-import-module-exports": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-import-next'],    rules: {      'import-next/no-import-module-exports': '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.