n/no-new-require
Disallow new require()
Also called node/no-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#
example.js1 problem
const app = new require("./app")Unexpected use of new operator with require;example.jsNo problems
const App = require("./app");
const app = new App();With parentheses around the require() call, new applies to the class:
example.jsNo problems
const app = new (require("./app"))();