no-new-require

Disallow new require(..)

deprecated

In new require("./server"), the new applies to require, not to what it returns, so you don't get an instance of the exported class. To create one in a single expression, put the require call in parentheses, or use two statements.

ESLint has deprecated this rule. Use n/no-new-require instead.

Examples#

example.js1 problem
const server = new require("./server");
example.jsNo problems
const Server = require("./server");
const server = new Server();

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