React Native:npm install <library>

时间:2019-03-24 18:57:41

标签: node.js react-native npm react-navigation npm-install

我正在使用react-navigation创建一个新的react native应用。

每次我执行npm install --save react-navigation时,都会看到一组与react-native-gesture-handler相关的警告。我正在使用react-native init Test创建一个全新的应用程序,下一步是安装react-navigation。

以下是警告和错误:

npm WARN jest-resolve@24.5.0 requires a peer of jest-haste-map@^24.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN jest-resolve-dependencies@24.5.0 requires a peer of jest-haste-map@^24.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN jest-snapshot@24.5.0 requires a peer of jest-haste-map@^24.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN react-navigation-drawer@1.3.0 requires a peer of react-native-gesture-handler@^1.0.12 but none is installed. You must install peer dependencies yourself.

npm WARN react-navigation-stack@1.1.1 requires a peer of react-native-gesture-handler@^1.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN @react-navigation/native@3.3.0 requires a peer of react-native-gesture-handler@* but none is installed. You must install peer dependencies yourself.

在我的代码中导入库并在iOS模拟器上运行时,出现如下错误:

Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(Unable to resolve module `react-native-gesture-handler` from `Documents/Code/Test/node_modules/@react-navigation/native/src/Scrollables.js`: Module `react-native-gesture-handler` does not exist in the Haste module map

我尝试删除应用中的node_modules文件夹,然后再次运行“ npm install”和“ npm install --save react-navigation”,但这确实解决了问题。

请求建议。

2 个答案:

答案 0 :(得分:3)

创建新应用后,安装react-native-gesture-handler库,然后需要安装Step1 : react-native init test//your app name Step2 : npm install --save react-navigation Step3 : npm install --save react-native-gesture-handler Step4 : react-native link react-native-gesture-handler 并链接该库。

{{1}}

答案 1 :(得分:0)

我遵循了Brijesh的建议,还不得不手动将库导入我的Xcode项目中。这是我遵循的步骤:

Step1:react-native初始化测试//您的应用名称

Step2:npm install --save react-navigation

Step3:npm install --save react-native-gesture-handler

Step4:react-native链接react-native-gesture-handler

Step5:右键单击Xco​​de“将文件添加到项目”中的库

Step6:/node_modules/react-native-gesture-handlers/ios/RNGestureHandler.xcodeproj

Step7:进入构建阶段并添加libRNGestureHandler.a

此问题已解决。