Skip to content

node/no-new-require Restriction

What it does

Warn about calling new on require.

Why is this bad?

The require function is used to include modules and might return a constructor. As this is not always the case this can be confusing.

Examples

Examples of incorrect code for this rule:

js
var appHeader = new require("app-header");

Examples of correct code for this rule:

js
var AppHeader = require("app-header");
var appHeader = new AppHeader();

How to use

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

json
{
  "plugins": ["node"],
  "rules": {
    "node/no-new-require": "error"
  }
}
bash
oxlint --deny node/no-new-require --node-plugin

References

Released under the MIT License.