【问题标题】:Unable to resolve module 'react-navigation' from .../App.js: Module 'react-navigation' does not exist in the Haste module map无法从 .../App.js 解析模块“react-navigation”:Haste 模块映射中不存在模块“react-navigation”
【发布时间】:2020-02-12 16:28:04
【问题描述】:

我刚刚设置了一个应用程序以开始构建它,并且我不断从我的 App.js 中收到此错误。这是 udemy 课程的一部分,在该课程中,我遵循了 T 的每条指令......所以我对到底发生了什么感到非常困惑,并且我遵循了我能找到的每一个建议。 Unable to resolve module react-navigation from /Users/3x7r3m157/Development/React-Native/food/App.js: Module react-navigation does not exist in the Haste module map.

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.
  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.

facebook::ReactABI35_0_0::JSIExecutor::defaultTimeoutInvoker(std::__1::function<void ()> const&, std::__1::function<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > ()>)
facebook::ReactABI35_0_0::JSIExecutor::defaultTimeoutInvoker(std::__1::function<void ()> const&, std::__1::function<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > ()>)
ED0789CD-8D80-39F4-9651-D8707D9C0337
ED0789CD-8D80-39F4-9651-D8707D9C0337
_dispatch_main_queue_callback_4CF
97285ACB-7B21-393A-ABF6-03F1DBB5D2A2
97285ACB-7B21-393A-ABF6-03F1DBB5D2A2
CFRunLoopRunSpecific
GSEventRunModal
UIApplicationMain
Exponent
0DC9A4BA-C3E8-3487-99DB-1B5C86597AF5

这是我的 App.js:

import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import SearchScreen from './src/screens/SearchScreen';

const navigator = createStackNavigator ({
  Search: SearchScreen
}, {
  initialRouteName: 'Search',
  defaultNavigationOptions: {
    title: 'BusinessSearch'
  }
});

export default createAppContainer(navigator);

【问题讨论】:

  • 你安装了 react-navigation 吗?你应该将你的 package.json 添加到这个问题中,因为错误似乎与它有关
  • 就是这样。细节中的魔鬼......谢谢!

标签: javascript ios reactjs react-native expo


【解决方案1】:

确保使用 npm i react-navigation 安装 react-navigation

【讨论】:

  • 谢谢!似乎是让我绊倒的小细节
【解决方案2】:

首先你必须使用 CMD 来运行这个命令。

  1. 如果你的系统是Windows,设置你的环境变量,将%SystemRoot%\system32添加到你的PATH我昨天遇到了这个错误,希望它对你有用。不要忘记重启你的电脑。

之后:

  1. 创建您的项目:npx expo-cli init &lt;projectname&gt;

然后:

  1. 安装反应导航:

    npm install react-navigation
    
  2. 安装依赖:

    expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view
    
  3. 安装 React 导航堆栈:

    npm install react-navigation-stack @react-native-community/masked-view
    
  4. 使用npm start -c启动应用并清除缓存。

更新导入 我们在即将到来的讲座中的导入现在看起来像这样:

import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';

错误?

如果您仍然看到有关包裹的错误和投诉,请执行以下操作:

  1. rm -r node_modules

  2. rm package-lock.json

  3. expo upgrade

  4. npm start -c

【讨论】:

    【解决方案3】:

    这样做肯定会奏效:

    npm install --legecy-peer-deps react-navigation
    

    npm install --legecy-peer-deps react-navigation --force
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-19
      • 2021-07-28
      • 1970-01-01
      • 2019-11-16
      • 1970-01-01
      相关资源
      最近更新 更多