无法从“App.js”解析“@react-navigation/native”-React Native + 如何解决?

Posted

技术标签:

【中文标题】无法从“App.js”解析“@react-navigation/native”-React Native + 如何解决?【英文标题】:Unable to resolve "@react-navigation/native" from "App.js" - React Native + How to Solve? 【发布时间】:2020-07-13 11:06:12 【问题描述】:

undefined 无法从App.js 解析模块@react-navigation/native:在项目中找不到@react-navigation/native。

如果您确定该模块存在,请尝试以下步骤:

 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules: rm -rf node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
- node_modules\react-native\Libraries\Utilities\HMRClient.js:307:41 in showCompileError
- node_modules\react-native\Libraries\Utilities\HMRClient.js:228:26 in client.on$argument_1
- node_modules\eventemitter3\index.js:181:39 in emit
- node_modules\metro\src\lib\bundle-modules\WebSocketHMRClient.js:80:20 in _ws.onmessage
- node_modules\event-target-shim\dist\event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\WebSocket\WebSocket.js:232:27 in _eventEmitter.addListener$argument_1
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue

Unable to resolve "@react-navigation/native" from "App.js"
Failed building javascript bundle.
Unable to resolve "@react-navigation/native" from "App.js"
Failed building JavaScript bundle.
Unable to resolve "@react-navigation/native" from "App.js"
Failed building JavaScript bundle.
> Unable to resolve "@react-navigation/native" from "App.js"
Unable to resolve "@react-navigation/native" from "App.js"
Failed building JavaScript bundle.
Error: Can't find react-native in package.json dependencies
Error: Can't find react-native in package.json dependencies

请帮助我。 电子邮件 ID:roy.sounak01@gmail.com

【问题讨论】:

是否遵循了本入门指南中的所有步骤? reactnavigation.org/docs/getting-started 【参考方案1】:
npm install @react-navigation/native

如果使用博览会:

expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view

同时运行:

npm install react-navigation

【讨论】:

【参考方案2】:

这个错误是因为你没有安装 react-navigation。

运行:

npm install react-navigation
npm start -- --reset-cache

【讨论】:

【参考方案3】:

最好的解决方案是删除你的 node_modules 和 package-lock.json 并尝试 npm install,它对我有用

【讨论】:

【参考方案4】:

我已经通过重新安装/更新这些软件包解决了这个问题。

npm install --save react-native-gesture-handler react-native-reanimated react-native-screens

解决问题

npm start -- --reset-cache

但执行以下操作确实成功:

删除

node_modules & package-lock.json 从手机中删除应用

run npm start -- --reset-cache
run app

【讨论】:

【参考方案5】:

尝试将此行添加到您的 metro.config.js

sourceExts: ['jsx', 'js', 'ts', 'tsx', 'json'],

【讨论】:

【参考方案6】:

另外,如果您使用 expo,您必须重新启动您的应用程序,执行 npm run... 来启动一个新服务器。

【讨论】:

以上是关于无法从“App.js”解析“@react-navigation/native”-React Native + 如何解决?的主要内容,如果未能解决你的问题,请参考以下文章

无法编译 ./src/App.js 找不到模块:无法解析

无法使用 ui 路由器解析状态

./src/App.js 模块未找到:无法解析 xxx 中的“@material-ui/data-grid”

未找到模块:无法解析“

js文件中无法导入vue文件

Webpack 4:找不到Entry模块中的ERROR:错误:无法解析'./src'