n/no-exports-assign

Disallow assigning to exports

fixable

Also called node/no-exports-assign

In a CommonJS file, exports is a local variable that starts out as module.exports. Assigning to it only changes the variable. The module still exports the old module.exports, so require() gets an empty object.

An assignment that sets module.exports in the same statement is allowed, because both then hold the same value.

--fix rewrites exports = .. to module.exports = ...

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"n/no-exports-assign" = "error" # or "warn"

Examples#

example.js1 problem
exports = {
  parse,
  stringify,
};
example.jsNo problems
module.exports = {
  parse,
  stringify,
};
example.jsNo problems
exports.parse = parse;
exports.stringify = stringify;
example.jsNo problems
module.exports = exports = { parse };
exports.stringify = stringify;