import/no-commonjs
eslint-plugin-import
No autofix
eslint.config.js
import importPlugin from "eslint-plugin-import";
export default [
{
plugins: { import: importPlugin },
rules: {
"import/no-commonjs": "error",
},
},
];var mod = require('./mod')
, common = require('./common')
, fs = require('fs')
, whateverModule = require('./not-found')
module.exports = { a: "b" }
exports.c = "d"var mod = require('./mod');module.exports = "foo"
module.exports = function rule(context) { return { /* ... */ } }module.exports = { x: "y" }
exports.z = function boop() { /* ... */ }Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
import/no-commonjs
eslint-plugin-import
import importPlugin from "eslint-plugin-import";
export default [
{
plugins: { import: importPlugin },
rules: {
"import/no-commonjs": "error",
},
},
];import/no-commonjs
import plugin · restriction
{
"plugins": [
"import"
],
"rules": {
"import/no-commonjs": "error"
}
}style/noCommonJs
style · since 1.9.0
{
"linter": {
"rules": {
"style": {
"noCommonJs": "error"
}
}
}
}Ensure all exports appear after other statements.
Prefer named exports to be grouped together in a single export declaration
Enforce the maximum number of dependencies a module can have.