[英]Requiring unknown module “ReactPerf” while integrating React Native with existing Android app
我正在尝试集成最新的React Native构建,并且我遇到了错误。 这是我的项目设置:
在app的build.gradle中,我导入react-native 0.24.1:
dependencies {
...
compile 'com.facebook.react:react-native:0.24.1'
}
项目的build.gradle指向Git子模块中的React Native:
allprojects {
repositories {
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$projectDir/../MyGitSubmodule/AwesomeProject/node_modules/react-native/android"
}
}
}
如在文档中描述的我另有集成在这里 ,并在该文档描述的升级在git的子模块RN 这里 。 我已将堆栈跟踪上传到此pastebin链接 。 要总结堆栈跟踪,因为格式化很难阅读,这些是亮点:
基本上,它抱怨模块ReactPerf
是必需的,但它不存在。
仅供参考, ReactPerf
模块: https : ReactPerf
。
从逻辑上讲,我们只需要告诉react-native来安装这个东西。
棘手的部分是,如果我们这样做:
npm install react-addons-perf
,然后我们将它安装在react-native
依赖项的“外部”。 因此,它会抱怨react-addons-perf
需要react
包。
解决方案是我们需要声明这个依赖“inside”react-native包。 换一种说法:
打开node_modules/react-native/package.json
。 你会找到
...
"dependencies": {
"absolute-path": "^0.0.0",
"art": "^0.10.0",
"babel-core": "~6.4.5",
"babel-plugin-external-helpers": "~6.4.0",
...
"react": "^0.14.5"
...
}
所以,我们需要做的就是为这些添加react-addons-perf
。
...
"dependencies": {
"absolute-path": "^0.0.0",
"art": "^0.10.0",
"babel-core": "~6.4.5",
"babel-plugin-external-helpers": "~6.4.0",
...
"react": "^0.14.5",
"react-addons-perf": "^0.14.5", // ADD THIS LINE FOR ReactPerf module
...
}
然后, npm install
。
根据我的经验,其余的错误,如Requiring module "8"
也将消失。
它对我有用,希望它也适合你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.