Skip to content

exportsAssignments

Prevent assignment to the exports variable in CommonJS modules.

✅ This rule is included in the node logical presets.

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.

var exports: any

The exports variable is available within a module's file-level scope, and is assigned the value of module.exports before the module is evaluated.

@sincev0.1.16

exports
= {};
var exports: any

The exports variable is available within a module's file-level scope, and is assigned the value of module.exports before the module is evaluated.

@sincev0.1.16

exports
= {
foo: number
foo
: 1,
bar: number
bar
: 2 };
var exports: any

The exports variable is available within a module's file-level scope, and is assigned the value of module.exports before the module is evaluated.

@sincev0.1.16

exports
=
const somethingElse: object
somethingElse
;

This rule is not configurable.

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.

Made with ❤️‍🔥 around the world by the Flint team and contributors.