Skip to content

feat: createRequireFromPath to createRequire #95

@AugustinMauroy

Description

@AugustinMauroy

Description

This codemod should migrate createRequireFromPath to createRequire. It's useful to migrate v12 to v14 or v16.

It's should handle both require() function and import statement.
It's should support both module node:module specifier.

Example

Before:

const { createRequireFromPath } = require('module');

// Using createRequireFromPath
const requireFromPath = createRequireFromPath('/path/to/module');
const myModule = requireFromPath('./myModule.cjs');

After:

 const { createRequire } = require('module');

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

REFS

https://nodejs.org/en/blog/release/v16.0.0
nodejs/node#37201
https://nodejs.org/docs/v22.17.1/api/deprecations.html#dep0130-modulecreaterequirefrompath

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    🏗 In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions