This recipe ensures REPL classes like REPLServer and Recoverable are properly instantiated with the new keyword.
Deprecation
Node.js deprecated calling REPL constructors without the new keyword. Classes must be instantiated with new.
See DEP0185 for more details.
Usage
Run this codemod with:
Before/After
What It Does
- Adds
new keyword before REPLServer() and Recoverable() calls
- Works with both direct imports and namespace imports (e.g.,
repl.REPLServer())
- Handles CommonJS and ESM module patterns
- Supports aliased imports (e.g.,
REPLServer as REPL)
Affected Classes
The following REPL classes are updated:
REPLServer - The main REPL server class
Recoverable - Error class for recoverable syntax errors
Example Scenarios
Creating a Custom REPL
Handling Recoverable Errors
Modern JavaScript requires all classes to be instantiated with the new keyword. This deprecation aligns Node.js REPL classes with standard JavaScript class syntax.