question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-native/cli not found error caused by `use_native_modules!`

See original GitHub issue

Description

iOS

After upgrading our brownfield project from 0.59.9 to 0.62.0 I encounter the following error when trying to run pod install:

> pod install

[!] Invalid `Podfile` file: [!] /Users/dude/.nvm/versions/node/v12.16.1/bin/node -e try {console.log(require('@react-native-community/cli').bin);} catch (e) {consol
e.log(require('react-native/cli').bin);}

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

Error: Cannot find module 'react-native/cli'
Require stack:
- /myapp/ios/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at [eval]:1:87
    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:1158:30)
    at evalScript (internal/process/execution.js:94:25) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/myapp/ios/[eval]' ]
}
.

 #  from /myapp/ios/Podfile:112
 #  -------------------------------------------
 #  
 >      use_native_modules!
 #      # Enables Flipper.
 #  -------------------------------------------

This error is caused by the following line in Podfile:

use_native_modules!

Going up the stream, I noticed that the error comes from this line in node_modules/@react-native-community/cli-platform-ios/native-modules.rb:

cli_resolve_script = "try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}"

After commenting out the use_native_modules! line in Podfile, the project builds and runs fine The unwanted side-effect is that autolinking doesn’t seem to work anymore

Android

A similar error happens on Android when doing gradle sync:

Gradle sync failed: Cause: internal/modules/cjs/loader.js:985  throw err;  
^Error: Cannot find module 'react-native/cli'Require stack:- /myapp/android/[eval]    
  at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)    
  at Function.Module._load (internal/modules/cjs/loader.js:864:27)    
  at Module.require (internal/modules/cjs/loader.js:1044:19)    
  at require (internal/modules/cjs/helpers.js:77: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:1158:30)    
  at evalScript (internal/process/execution.js:94:25) {  code: 'MODULE_NOT_FOUND',  requireStack: [    '/myapp/android/[eval]'  ]}
				Consult IDE log for more details (Help | Show Log) (256 ms)

This error is caused by the following line in settings.gradle:

apply from: file("../src/node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

Again going up the stream, I noticed that the error comes from this line in node_modules/@react-native-community/cli-platform-android/native-modules.gradle:

def cliResolveScript = "console.log(require('react-native/cli').bin);"

And, like iOS, after commenting out the apply from: line in settings.gradle, the project builds and runs fine. The unwanted side-effect here, as well, is that it seems like autolinking doesn’t work anymore

Environment

> yarn exec react-native info
yarn exec v1.22.4
info Fetching system and libraries information...
System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
    Memory: 874.98 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.16.1 - /var/folders/bg/l9cbxs955zsdlj3gl697fsk80000gp/T/yarn--1587152442523-0.833201365558697/node
    Yarn: 1.22.4 - /var/folders/bg/l9cbxs955zsdlj3gl697fsk80000gp/T/yarn--1587152442523-0.833201365558697/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK: Not Found
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6241897
    Xcode: 11.4/11E146 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_102 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: 0.62.0 => 0.62.0 
  npmGlobalPackages:
    *react-native*: Not Found
✨  Done in 2.34s.
  • The structure of the project is:
myapp  __ ios/
      |__ android/
      |__ src/ __ index.js
              |__ package.json
              |__ node_modules/
  • I uninstalled the global react-native-cli as per recommendations in the README file.

react-native-cli – an optional global convenience package, which is a proxy to @react-native-community/cli and global installation helper. Please consider it legacy, because it’s not necessary anymore.

I use npx or yarn exec for all react-native commands, to use locally installed binaries.

BTW, the error stays the same with of without the global react-native-cli installed

  • I followed the instructions in the README Updating the CLI section to bring all the cli packages up-to-date:
> yarn list --pattern @react-native-community/cli
yarn list v1.22.4
├─ @react-native-community/cli-debugger-ui@4.7.0
├─ @react-native-community/cli-platform-android@4.7.0
├─ @react-native-community/cli-platform-ios@4.7.0
├─ @react-native-community/cli-tools@4.7.0
├─ @react-native-community/cli-types@4.7.0
└─ @react-native-community/cli@4.7.0
✨  Done in 0.73s.

Steps To Reproduce

I tried to reproduce with a brand new test project created via, using the exact same environment

yarn exec react-native init New0620 --version 0.620

but, I can’t reproduce neither the iOS nor the Android issue.

Expected Results

I should be able to uncomment use_native_modules! in Podfile and run pod install without this error I should be able to uncomment apply from: file("../src/node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) in settings.gradle and be able to run the gradle sync without this error

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:25 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
RebeccaAouizeratscommented, Apr 13, 2021

In my case, it was failing on node 14 but working on node 10. It is just a temporary solution, I’m trying to find a fixed solution.

2reactions
mfhardingcommented, Jun 16, 2020

Doing the exact opposite of the recommendations fixed this for me. I installed @react-native-community/cli. For some reason for upgraded projects @react-native-community/cli isn’t imported correctly.

npm i --save @react-native-community/cli

You know what they say when you are desperate to hit a deadline yolo this shit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native ios Podfile issue with "use_native_modules!"
For me, I deleted the node_modules and installed again by using npm install . After that, I navigated to /ios folder and ran...
Read more >
iOS Native Modules
To get started, open up the iOS project within your React Native application in Xcode. You can find your iOS project here within...
Read more >
React Native SDK Troubleshooting - Visual Studio App Center
'React/RCTDefines.h' file not found ... This error appears when RN core libraries aren't referenced correctly, which can be caused by different ...
Read more >
react-native ios Podfile issue with "use_native_modules!"
3 - If you didn't find after you run yarn install - means you have old cache node_modules in your machine and you...
Read more >
Addressing common errors in React Native - LogRocket Blog
The command not found error has two potential causes: either you do not have the CLI installed on your local machine, or you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found