exportsAssignments
Prevent assignment to the
exportsvariable in CommonJS modules.
✅ This rule is included in the node logical preset.
In CommonJS modules, assigning directly to the exports variable breaks the reference to module.exports, which means your exports won’t work as expected.
The exports variable is initially a reference to module.exports, but reassigning it creates a new local binding that doesn’t affect the actual module exports.
To export values, always use module.exports directly, or modify properties on exports without reassigning it.
Examples
Section titled “Examples”exports = {};
exports = { foo: 1, bar: 2 };
exports = somethingElse;module.exports.foo = 1;
exports.bar = 2;
module.exports = {};
module.exports = exports = {};
exports = module.exports = {};Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you use an unusual code pattern that intentionally needs to remove the original reference to exports, this rule may not be for you.
However, doing so may make it harder to understand your code or migrate it to the more modern ECMAScript Modules (ESM) syntax.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
n/no-exports-assign - Oxlint:
node/no-exports-assign