n/no-new-require

Disallow `new require()`

new require("./app") applies new to require, not to what require returns. You get the class the module exports, not an instance of it.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"n/no-new-require" = "error" # or "warn"

Examples#

Reported:

const app = new require("./app");

Not reported:

const App = require("./app");
const app = new App();

With parentheses around the require() call, new applies to the class:

const app = new (require("./app"))();