Registry
Nnodejs avatar

nodejs/create-require-from-path

Handle DEP0130 via transforming `createRequireFromPath` to `createRequire`.

nodejs313 executions

  • transformation
  • migration
Connect a repo
npx codemod @nodejs/create-require-from-path

createRequireFromPath DEP0130

This recipe transforms the usage of createRequireFromPath to use the createRequire function from the node:module module.

See DEP0130.

Example

diff
- const { createRequireFromPath } = require('node:module');
+ const { createRequire } = require('node:module');

  // Using createRequireFromPath
- const requireFromPath = createRequireFromPath('/path/to/module');
+ // Using createRequire with a specific path
+ const require = createRequire('/path/to/module');
- const myModule = requireFromPath('./myModule.cjs');
+ const myModule = require('./myModule.cjs');

Ready to evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.