This recipe provides a guide for migrating from the deprecated instantiation of node:repl classes without new to proper class instantiation in Node.js.
See DEP0185.
const repl = require("node:repl");
const { REPLServer, Recoverable } = require("node:repl");
import { REPLServer } from "node:repl";
const { REPLServer: REPL } = await import("node:repl");
// Missing 'new' keyword
- const server1 = repl.REPLServer();
+ // With 'new' keyword
+ const server1 = new repl.REPLServer();
- const server2 = REPLServer({ prompt: ">>> " });
+ const server2 = new REPLServer({ prompt: ">>> " });
- const server3 = repl.Recoverable();
+ const server3 = new repl.Recoverable();
- const error = Recoverable(new SyntaxError());
+ const error = new Recoverable(new SyntaxError());
- const server4 = REPL({ prompt: ">>> " });
+ const server4 = new REPL({ prompt: ">>> " });