createRequireFromPath function to use the modern createRequire function from the node:module module.
What It Does
The codemod transforms:createRequireFromPathimport/require →createRequirecreateRequireFromPath(path)calls →createRequire(path)- Variable names from
requireFromPath→require(where appropriate)
Usage
Example
- CommonJS
- ESM
Before
After
Why Migrate?
createRequireFromPath was deprecated in favor of createRequire, which:
- Has a clearer, more concise name
- Provides the same functionality with a better API
- Aligns with Node.js module system conventions
- Is the recommended approach going forward