Skip to content
← Back to rules

node/exports-style Style

🚧 An auto-fix is planned for this rule, but not implemented at this time.

What it does ​

Enforce either module.exports or exports.

Why is this bad? ​

module.exports and exports are the same instance by default. But those come to be different if one of them is modified.

js
module.exports = {
  foo: 1,
};

exports.bar = 2;

In this case, exports.bar will be lost since only the instance of module.exports will be exported.

Examples ​

Examples of incorrect code for the "module.exports" option:

js
exports.foo = 1;
exports.bar = 2;

Examples of correct code for the "module.exports" option:

js
module.exports = {
  foo: 1,
  bar: 2,
};
module.exports.baz = 3;

Examples of incorrect code for the "exports" option:

js
module.exports = {
  foo: 1,
  bar: 2,
};
module.exports.baz = 3;

Examples of correct code for the "exports" option:

js
exports.foo = 1;
exports.bar = 2;

Configuration ​

The 1st option ​

type: "module.exports" | "exports"

"module.exports" ​

Requires module.exports and disallows exports

"exports" ​

Requires exports and disallows module.exports

The 2nd option ​

This option is an object with the following properties:

allowBatchAssign ​

type: boolean

default: false

If this option is set to true, module.exports = exports = obj are allowed.

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["node"],
  "rules": {
    "node/exports-style": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["node"],
  rules: {
    "node/exports-style": "error",
  },
});
bash
oxlint --deny node/exports-style --node-plugin

Version ​

This rule was added in v1.76.0.

References ​