Skip to content

Disallow assignment to exports (node/no-exports-assign) #1400

@feross

Description

@feross

https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-exports-assign.md

Assigning to the exports variable does not work as expected.

// This assigned object is not exported.
// You need to use `module.exports = { ... }`.
exports = {
    foo: 1
}

This rule is aimed at disallowing exports = {}, but allows module.exports = exports = {} to avoid conflict with node/exports-style rule's allowBatchAssign option.

👍 Examples of correct code for this rule:

/*eslint node/no-exports-assign: error */

module.exports.foo = 1
exports.bar = 2

module.exports = {}

// allows `exports = {}` if along with `module.exports =`
module.exports = exports = {}
exports = module.exports = {}

👎 Examples of incorrect code for this rule:

/*eslint node/no-exports-assign: error */

exports = {}

I don't expect this to be controversial

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions