Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'core-js/modules/es.array.find' #249

Open
minhtranite opened this issue Nov 5, 2019 · 6 comments
Open

Cannot find module 'core-js/modules/es.array.find' #249

minhtranite opened this issue Nov 5, 2019 · 6 comments
Labels

Comments

@minhtranite
Copy link

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

@threepointone
Copy link
Contributor

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?

@minhtranite
Copy link
Author

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 .

test.zip

@threepointone
Copy link
Contributor

threepointone commented Nov 9, 2019

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!

@jasontk19
Copy link

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?

@anilanar
Copy link

anilanar commented Oct 23, 2020

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.

@dartess
Copy link

dartess commented Nov 26, 2020

TL;DR: Run npx react-codemod outside 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants