facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.22k stars 626 forks source link

Cannot find module is-core-module\index.js While processing metro-react-native-babel-preset #992

Open Bilal-Abdeen opened 1 year ago

Bilal-Abdeen commented 1 year ago

Description

When I execute npx react-native run-android, I get the following error message. To isolate the issue, I tried creating a brand new testing app. This occurs on MS Windows 10 with an Android Emulator and an Android physical device. This problem does NOT occur on macOS with an iOS simulator.

error: index.js: [BABEL] C:\react\Casual_Job\test\index.js: Cannot find module 'C:\react\Casual_Job\test\node_modules\is-core-module\index.js' (While processing: "C:\\react\\Casual_Job\\test\\node_modules\\metro-react-native-babel-preset\\src\\index.js")

React Native Version

0.71.8

Output of npx react-native info

info Fetching system and libraries information... System: OS: Windows 10 10.0.19042 CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz Memory: 15.82 GB / 31.90 GB Binaries: Node: 18.16.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD Watchman: 20220614.153706.0 - C:\ProgramData\chocolatey\bin\watchman.EXE SDKs: Android SDK: Not Found Windows SDK: AllowAllTrustedApps: Disabled Versions: 10.0.17763.0, 10.0.19041.0 IDEs: Android Studio: AI-212.5712.43.2112.8512546 Visual Studio: Not Found Languages: Java: 11.0.15 - C:\Program Files\Common Files\Oracle\Java\javapath\javac.EXE npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.8 => 0.71.8 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

npx react-native init test
cd test
npx react-native run-android

Snack, code example, screenshot, or link to a repository

N/A

Bilal-Abdeen commented 1 year ago

The problem was fixed by executing the following.

npm start -- --reset-cache
rd %localappdata%\Temp\metro-cache /s /q & del %localappdata%\Temp\haste-map* & npm cache clean --force & cd android & gradlew clean & cd .. & rd .\android\build /q /s
rd /q /s C:\Users\Bilal\AppData\Roaming\npm-cache                 ### replace Bilal with your user name
rd /q /s node_modules & del package-lock.json & del yarn.lock
npm install
cortinico commented 1 year ago

@Bilal-Abdeen is this happening consistently on every new Windows project?

Bilal-Abdeen commented 1 year ago

@cortinico I have tried it around 10 times. I think it happened around 90% (if 100%) of the time. However, I discovered that only clearing the cache npm start -- --reset-cache "might" be enough to fix it. If not, I am almost certain the following would be enough to fix it (rather than the 6 statements I mentioned in my previous comment above.)

npm start -- --reset-cache
rd /q /s node_modules 
npm install

More importantly, it seems that the 3 statements above are required after the installation of some libraries. To make it easier for me, I made a batch file for them! I am not sure if only npm start -- --reset-cache would be enough, but I got furious and tired of trying. So, I did not try npm start -- --reset-cache enough times to conclude if it is good enough!

cortinico commented 1 year ago

Passing over to metro as using --reset-cache is just a workaround and definitely not a solution. Folks from Metro might want to investigate more what's going on.