Cli: Cannot find module '@react-native-community/cli'

Created on 28 May 2019  Â·  29Comments  Â·  Source: react-native-community/cli

Environment

Running 'react-native info' throws that error as well.

internal/modules/cjs/loader.js:584
throw err;
^

Error: Cannot find module '@react-native-community/cli'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (E:\Projects\Hady\ProcoorCommunication\node_modules\react-native\cli.js:12:11)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)

Description

Running 'react-native init AppName' results in this error (Cannot find module '@react-native-community/cli')

internal/modules/cjs/loader.js:584
throw err;
^

Error: Cannot find module '@react-native-community/cli'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (E:\Projects\Hady\ProcoorCommunication\node_modules\react-native\cli.js:12:11)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)

Reproducible Demo

Run 'react-native init AppName' after it finishes it will try to run cli.js at 'node_modules\react-native\local-cli\cli.js' but it fails and throws that error 'Error: Cannot find module '@react-native-community/cli''

bug

Most helpful comment

Should be fixed in cli-platform-android & cli-platform-ios 3.1.4.
Please update the @react-native-community/cli to the latest version.

All 29 comments

That's likely because you installed 1.9.6 which was a bad release, please remove @react-native-community/cli and install deps once again.

@thymikee I am running 'react-native init App' and it fails after yarn install the modules so my package.json looks like this after that.

{
  "name": "ProcoorCommunication",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/cli.js start"
  },
  "dependencies": {
    "react-native": "0.59.8"
  }
}

The only message i am getting is 'Error: Cannot find module '@react-native-community/cli' and no so much to go on from there i uninstalled the global react-native-cli and reinstalled but still the same error also removing '@react-native-community/cli' using yarn fails and gives this message 'This module isn't specified in a manifest.' removing it manually and running yarn yields nothing.

Which version of @react-native-community/cli is installed? Can you share this repo with me? I've ran init today with the same version and it works just fine. I'm assuming this is something with your environment.

@thymikee I guess it was a long file path issue it got resolved when i run the command on the root drive.

Ah, Windows...

Facing this issue again after 3.1.0 release of @react-native-community/cli. Downgraded @react-native-community/cli-platform-ios from 3.1.0 to 3.0.0 and now is working again.

Added "@react-native-community/cli-platform-ios": "3.0.0" to package.json. Run npm install and then pod install.

Thanks @vitorplopes for your timely comment, did the trick!

@vitorplopes thanks, issue solved.

Facing this issue again after 3.1.0 release of @react-native-community/cli. Downgraded @react-native-community/cli-platform-ios from 3.1.0 to 3.0.0 and now is working again.

Added "@react-native-community/cli-platform-ios": "3.0.0" to package.json. Run npm install and then pod install.

Not work

System:
   OS: Windows 10 10.0.18362
   CPU: (12) x64 AMD Ryzen 5 1600 Six-Core Processor
   Memory: 8.03 GB / 15.93 GB
Binaries:
   Node: 13.8.0 - C:\Program Files\nodejs\node.EXE
   npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD
SDKs:
    Android SDK:
    API Levels: 29
    Build Tools: 29.0.2
    System Images: android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 
Atom
   IDEs:
   Android Studio: Version  3.5.0.0 AI-191.8026.42.35.6010548
npmPackages:
   react: 16.9.0 => 16.9.0 
   react-native: 0.61.5 => 0.61.5

We've recently released a patch that should fix these. Please update the @react-native-community/cli to the latest version and test again.

install this. npm i @react-native-community/cli

@thymikee
I updated the cli according to how the doc says.
But I still get the following version when I run npm list @react-native-community/cli,

└─┬ [email protected]
  └── @react-native-community/[email protected]

And the version you have released is v3.1.3.
Am I missing something?

@YeshanJay CLI is a set of packages, which are versioned independently. The package that's affected for this issue is @react-native-community/cli-platform-android, which got promoted to 3.1.3.
FYI, with yarn you could do yarn list --pattern @react-native-community/cli which would output all packages related to RN CLI

@thymikee Got it mate.
Just checked the package-lock.json.
Both cli-platform-android and cli-platform-android have the version 3.1.3

Still getting this error though when I run npx react-native run-android...

:ReactNative:Unexpected empty result of running '[node, -e, console.log(require('@react-native-community/cli').bin);]' command.
:ReactNative:Running '[node, -e, console.log(require('@react-native-community/cli').bin);]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script '/Users/yeshanjay/Documents/Projects/MyReactNativeApp/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 170

* What went wrong:
A problem occurred evaluating script.
> internal/modules/cjs/loader.js:976  throw err;  ^Error: Cannot find module '@react-native-community/cli'Require stack:- /Users/yeshanjay/Documents/Projects/MyReactNativeApp/android/[eval]    
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:973:15)    
at Function.Module._load (internal/modules/cjs/loader.js:855:27)    
at Module.require (internal/modules/cjs/loader.js:1033:19)    
at require (internal/modules/cjs/helpers.js:72:18)    
at [eval]:1:13    at Script.runInThisContext (vm.js:120:20)    
at Object.runInThisContext (vm.js:311:38)    
at Object.<anonymous> ([eval]-wrapper:10:26)    
at Module._compile (internal/modules/cjs/loader.js:1144:30)    
at evalScript (internal/process/execution.js:94:25) {  code: 'MODULE_NOT_FOUND',  requireStack: [    '/Users/yeshanjay/Documents/Projects/MyReactNativeApp/android/[eval]'  ]}

What happens if you run

node -e "console.log(require('@react-native-community/cli').bin);"

or

node -e console.log(require('@react-native-community/cli').bin);

@thymikee .. Ran node -e "console.log(require('@react-native-community/cli').bin);",

And got this..

internal/modules/cjs/loader.js:976
  throw err;
  ^

Error: Cannot find module '@react-native-community/cli'
Require stack:
- /Users/yeshanjay/Documents/Projects/MyReactNativeApp/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:973:15)
    at Function.Module._load (internal/modules/cjs/loader.js:855:27)
    at Module.require (internal/modules/cjs/loader.js:1033:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at [eval]:1:13
    at Script.runInThisContext (vm.js:120:20)
    at Object.runInThisContext (vm.js:311:38)
    at Object.<anonymous> ([eval]-wrapper:10:26)
    at Module._compile (internal/modules/cjs/loader.js:1144:30)
    at evalScript (internal/process/execution.js:94:25) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/yeshanjay/Documents/Projects/MyReactNativeApp/[eval]'
  ]
}

@thymikee . Do I need to install the @react-native-community/cli package globally??

And also note that it's not there in my package.json.

Same issue +1

Same error

Ok, I know what's happening. We rely on @react-native-community/cli being hoisted same as @react-native-community/cli-platform-android. While this is true for Yarn, it's not always true for npm, which bails to hoist it:
image

Nevertheless, this is an issue on our side, which we need to address. Please bare with us while we're working on a fix.

@thymikee Thanks for the response mate. Looking forward to the fix 💯

I was having the same issue just a minute ago. We are using AppCenter to build the application and it was failing.

node -e "console.log(require('@react-native-community/cli').bin);" was giving the Error: Cannot find module '@react-native-community/cli' error.

I've deleted node_modules and package-lock.json. After running npm i, used npm i @react-native-community/cli. Now, @react-native-community/cli version is 4.0.1 and everything works as expected.

Thanks!

Should be fixed in cli-platform-android & cli-platform-ios 3.1.4.
Please update the @react-native-community/cli to the latest version.

@thymikee Works like a charm mate... thanks a lot for the quick fix! 🚀

Justs a heads up, somehow this breaks my android build on appcenter. I'm getting Error: Cannot find module 'react-native/cli'.

Definitely could be appcenter related, I'm trying to see if they cache the build folders right now.

@thymikee I guess it was a long file path issue it got resolved when i run the command on the root drive.

This is true. I had my project with long path with cyrillic symbols. Then, I just moved the project to root E:\ disk

tons of issues are caused by long file path with unrecognized symbols in Android Studio

with cli I have the same a problem. With Expo it's works

Hello - I am also having this problem on our CI/CD Machine...

react native -v:
react-native-cli: 2.0.1
react-native: 0.63.4

react native info:
module.js:559
throw err;
^

Error: Cannot find module '@react-native-community/cli'
at Function.Module._resolveFilename (module.js:557:15)
at Function.Module._load (module.js:484:25)
at Module.require (module.js:606:17)
at require (internal/module.js:11:18)
at Object. (/opt/[*]/workspace/GDAT_GMSA_173561_ReactNative/node_modules/react-native/cli.js:13:11)
at Module._compile (module.js:662:30)
at Object.Module._extensions..js (module.js:673:10)
at Module.load (module.js:575:32)
at tryModuleLoad (module.js:515:12)
at Function.Module._load (module.js:507:3)

Was this page helpful?
0 / 5 - 0 ratings