简体   繁体   中英

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

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'

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.

出于某种奇怪的原因,它与 yarn install 一起工作,然后进行 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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM