Linter · Rules
n/no-exports-assign
Disallow assigning to exports
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
Reported:
exports = {
parse,
stringify,
};
Not reported:
module.exports = {
parse,
stringify,
};
exports.parse = parse;
exports.stringify = stringify;
module.exports = exports = { parse };
exports.stringify = stringify;