react-codemod
react-codemod copied to clipboard
Cannot find module 'core-js/modules/es.array.find'
I run command npx react-codemod rename-unsafe-lifecycles src and got this error:
Error: Cannot find module 'core-js/modules/es.array.find'
Require stack:
- /Users/minhtran/.npm/_npx/24243/lib/node_modules/react-codemod/transforms/rename-unsafe-lifecycles.js
- /Users/minhtran/.npm/_npx/24243/lib/node_modules/react-codemod/node_modules/jscodeshift/src/Worker.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/Users/minhtran/.npm/_npx/24243/lib/node_modules/react-codemod/transforms/rename-unsafe-lifecycles.js:10:1)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Module._compile (/Users/minhtran/.npm/_npx/24243/lib/node_modules/react-codemod/node_modules/pirates/lib/index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Object.newLoader [as .js] (/Users/minhtran/.npm/_npx/24243/lib/node_modules/react-codemod/node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:812:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/minhtran/.npm/_npx/24243/lib/node_modules/react-codemod/transforms/rename-unsafe-lifecycles.js',
'/Users/minhtran/.npm/_npx/24243/lib/node_modules/react-codemod/node_modules/jscodeshift/src/Worker.js'
]
}
It run on node v12.12.0 and npm v6.12.1
I'm unable to reproduce this on my machine with the same node/npm version. Could you help by isolating this to a single file/code pattern that this fails on?
Hi!, The error happen when run command above in a project use babel with core-js@3.
Please download this project, run npm install and run npx react-codemod rename-unsafe-lifecycles .
Nice catch! I can reproduce it now.
The workaround (for now) is to run react-codemod from outside the project folder. So instead of
cd my-project
npx react-codemod rename-unsafe-lifecycles
You can run
npx react-codemod rename-unsafe-lifecycles my-project
This will ensure that react-codemod will use its own dependency versions, and run the transforms as expected.
I'll make a proper fix for this later, and will leave this issue open until then. Thanks again!
This same underlying issue, which appears to be running react-codemod inside a project dir with a different babel config/dependencies than react-codemod expects, also gave me some trouble. In my case, I ran into the following error when running npx react-codemod sort-comp . --dry --print:
Transformation error (regeneratorRuntime is not defined)
ReferenceError: regeneratorRuntime is not defined
This seems like something that people might regularly run into. Would it be worth updating the readme to instruct people to run react-codemod from outside their project dir in all cases until this can be fixed?
Google brought me here and @jasontk19's answer helped.
TL;DR: Run npx react-codemod outside your project's directory.
If you don't, react-codemod uses dependencies inside your node_modules which most likely won't work.
If where you run react-codemod is not a git repository, you need to run npx react-codemod --force.
@dartess Thanks for the tip.
TL;DR: Run
npx react-codemodoutside your project's directory.
If the parent directory is not a git repository, you will need to add the flag --force to run react-codemod