[英]Integrate react-native version 0.62.2 into existing IOs app error
Following react-native document to integrate react-native to existing IOs app.按照 react-native 文档将 react-native 集成到现有的 IOs 应用程序。 The structure of directory as document to integrate is作为要集成的文档的目录结构是
android/
ios/
Podfile
#...other ios file
node_modules/
react-native
react
@react-native-community
package.json
....
So that when run pod install from Podfile can call function use_native_modules这样当从 Podfile 运行 pod install 时,可以调用 function use_native_modules
require_relative './libs/react-native-libs/node_modules/@react-native-community/cli-platform-ios/native_modules'
...
use_native_modules!
so I add react-native-integrate module like as a part of my IOs project like this所以我添加了 react-native-integrate 模块,就像我的 IOs 项目的一部分一样
my_ios_project
Podfile
libs/
... other modules
react-native-integrate
node_modules
react-native
@react-native-community
react
package.json
And then I change the path of relative-module:然后我改变了相对模块的路径:
require_relative './libs/react-native-libs/node_modules/@react-native-community/cli-platform-ios/native_modules'
...
use_native_module!
But the problem is in native_modules files and others libraries in node_modules use absolute require
.但问题在于 native_modules 文件和 node_modules 中的其他库使用 absolute require
。 For example in @react-community/cli-platform-ios/native_module.rb
there is a line such as例如在@react-community/cli-platform-ios/native_module.rb
有一行如
cli_resolve_script = "try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('@react-native/cli'))}"
that require absolute path '@react-native-community'.需要绝对路径'@react-native-community'。 So that when I run Pod install
my pod file from parent directory the node
can not recognize my children module so that it cause error.因此,当我从父目录运行Pod install
我的 pod 文件时, node
无法识别我的子模块,从而导致错误。
As I know the node_module 'spaths list is basically a list of node_modules directories under every directory from the current directory to the root directory.据我所知, node_module 的路径列表基本上是从当前目录到根目录的每个目录下的 node_modules 目录列表。 And the current directory is that the directory of the Podfile that call require 'native_module.rb' Could you please give me a solution solve this problem like add node path from children directory or something else?当前目录是调用 require 'native_module.rb' 的 Podfile 的目录,你能给我一个解决这个问题的解决方案吗,比如从子目录添加节点路径或其他什么? Thank you.谢谢你。
I found a solution:我找到了一个解决方案:
main
添加 package.json 文件在根 ios 与属性main
cli-platform-ios
and cli-platform-android
:在根 ios 项目中添加 react-native.config.js,编辑cli-platform-ios
和cli-platform-android
路径:'use strict';
const ios = require('./node_modules/@react-native-community/cli-platform-ios');
const android = require('./node_modules/@react-native-community/cli-platform-android');
module.exports = {
commands: [...ios.commands, ...android.commands],
platforms: {
ios: {
linkConfig: ios.linkConfig,
projectConfig: ios.projectConfig,
dependencyConfig: ios.dependencyConfig,
},
android: {
linkConfig: android.linkConfig,
projectConfig: android.projectConfig,
dependencyConfig: android.dependencyConfig,
},
}
};
pod install
again再次运行pod install
Checkout my demo here: https://github.com/lehoangnam97/demo-intergrate-rn-on-ios在这里查看我的演示: https://github.com/lehoangnam97/demo-intergrate-rn-on-ios
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.