react-native: Cannot find module '@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.<anonymous> (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.<anonymous> (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’’

package.json

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

For some weird reason it worked with yarn install and then doing the pod install

installing this solve the issue. npm i @react-native-community/cli

@davidsalib that sounds like faulty installation, since yarn normally detects the CLI. Please try initializing again. Or npx react-native uses global version. Use npx --ignore-existing react-native to avoid using global (and please uninstall any global react-native/react-native-cli packages)

Starting with a fresh project (npx react-native init MyTestApp), when I run npm list @react-native-community/cli I get:

MyTestApp@4.1.0 /Users/user/Desktop/Projects/MyTestApp
└── (empty)

The bigger issue is that I can’t run pod install, I get:

    throw err;
    ^

Error: Cannot find module '/MyTestApp/node_modules/@react-native-community/cli/build/bin.js

However, I see @react-native-community/cli/build/bin.js in node_modules

Thanks @thymikee! Turns out the issue was my node version.

incase it helps anybody in the future, this was the issue:

error @typescript-eslint/parser@1.13.0: The engine "node" is incompatible with this module. Expected version "^6.14.0 || ^8.10.0 || >=9.10.0". Got "8.3.0"