react-native integration with existing native project getting error Cannot find module 'react-native/cli'

Viewed 608

I am trying to integrate latest RN project into native project. Both project are in separate directories that means my native project does not exist in predefined ios folder.

versions:

RN Native: 0.63.3 @react-native-community/cli: 4.13.0 installed globally using yarn global add @react-native-community/cli.

I am getting error stating react-native-community package not found.

My pod file is mentioned below:

require_relative '../AwesomeProject/node_modules/react-native/scripts/react_native_pods'
require_relative '../AwesomeProject/node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'

use_frameworks!


def main_pods
    config = use_native_modules!
    use_react_native!(:path => config["reactNativePath"])
end


target 'NativeFramework' do
    main_pods
end

target 'Example' do
    main_pods
end

Error:


[!] Invalid `Podfile` file: [!] /usr/local/bin/node -e try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}

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

Error: Cannot find module 'react-native/cli'
3 Answers

You say you've installed @react-native-community/cli with Yarn. The error message indicates that may not be working for you. It's not surprising, because your Podfile says it can be found in a subdirectory of your project.

Why not install with npm and see what happens?

  1. cd to AwesomeProject
  2. npm i @react-native-community/cli

Alternatively, change your Podfile so it refers to the global location.

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

After so much times passed, I found the problem is that the android-project dir must be in the react-native-project dir !

react-native": "0.68.2" java11 Apple M1 Pro


Integration ReactNative with Existing Apps

https://reactnative.dev/docs/integration-with-existing-apps

Problems

  • Error: Cannot find module 'react-native/cli'

    After so much times passed, I found the problem is that the android-project dir must be in the react-native-project dir !

Related