【问题标题】:Can't resolve react-navigation/core无法解决反应导航/核心
【发布时间】:2021-12-06 14:39:16
【问题描述】:

我正在尝试构建一个带有一些导航的 React Native 应用程序,但每当我构建它时都会出现此错误,我正在使用 expo 来构建应用程序:

Android Bundling failed 6098ms
While trying to resolve module `@react-navigation/core` from file `/Users/laurent/Documents/Delivery/Tek3/DEV/B-DEV-501-LYN-5-1-redditech-laurent.cazette/node_modules/@react-navigation/native/src/ResourceSavingSceneView.js`, the package `/Users/laurent/Documents/Delivery/Tek3/DEV/B-DEV-501-LYN-5-1-redditech-laurent.cazette/node_modules/@react-navigation/core/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/laurent/Documents/Delivery/Tek3/DEV/B-DEV-501-LYN-5-1-redditech-laurent.cazette/node_modules/@react-navigation/core/lib/module/index.js`. Indeed, none of these files exist:

  * /Users/laurent/Documents/Delivery/Tek3/DEV/B-DEV-501-LYN-5-1-redditech-laurent.cazette/node_modules/@react-navigation/core/lib/module/index.js(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
  * /Users/laurent/Documents/Delivery/Tek3/DEV/B-DEV-501-LYN-5-1-redditech-laurent.cazette/node_modules/@react-navigation/core/lib/module/index.js/index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)

我想我已经安装了所有依赖项,但这是我的 package.json 以防我忘记了任何东西:

{
  "main": "index.js",
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "start": "react-native start"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/core": "react-navigation/core",
    "@react-navigation/native": "react-navigation/native",
    "@react-navigation/stack": "5.9.0",
    "expo": "~42.0.1",
    "expo-splash-screen": "~0.11.2",
    "expo-status-bar": "~1.0.4",
    "expo-updates": "~0.8.1",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "0.63.4",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-paper": "^4.9.2",
    "react-native-reanimated": "~2.2.0",
    "react-native-safe-area-context": "^3.3.2",
    "react-native-screens": "~3.4.0",
    "react-native-svg": "^12.1.1",
    "react-native-unimodules": "0.14.10",
    "react-native-vector-icons": "^8.1.0",
    "react-native-web": "^0.17.5",
    "react-navigation": "^4.4.4",
    "react-navigation-stack": "^2.10.4",
    "styled-components": "^5.3.1",
    "styled-system": "^5.1.5"
  },
  "devDependencies": {
    "@babel/core": "^7.9.0"
  },
  "private": true
}

我已经尝试更新 metro.config.js :

const { getDefaultConfig } = require('expo/metro-config');

module.exports = {
    resolver: {
      /* resolver options */
      sourceExts: ['jsx', 'js', 'ts', 'tsx'],
    },
    maxWorkers: 2,
    transformer: {
      getTransformOptions: async () => ({
        transform: {
          experimentalImportSupport: false,
          inlineRequires: false,
        },
      }),
    },
  };
module.exports = getDefaultConfig(__dirname);

你们有什么想法吗?

【问题讨论】:

    标签: javascript react-native react-navigation react-navigation-stack


    【解决方案1】:

    试试这个:

    1. 安装 react-navigation 模块。
    2. 重新构建您的项目。
    3. 通过停止当前的打包程序重新启动打包程序 打包器,然后使用 react-native 再次启动打包器 开始。

    Unable to resolve module 'react-navigation'

    【讨论】:

    • 尝试用 yarn add ... --force 重新安装,但没有结果,还尝试用 expo start -c 重新运行,以便清空缓存
    【解决方案2】:

    你为什么会这样?

    "@react-navigation/core": "react-navigation/core",
    "@react-navigation/native": "react-navigation/native",
    

    它们必须是正确的版本号。按照官网文档安装包:

    https://reactnavigation.org/docs/getting-started

    https://reactnavigation.org/docs/stack-navigator/

    expo install react-native-screens react-native-safe-area-context react-native-gesture-handler
    yarn add @react-navigation/native @react-navigation/stack
    

    并从您的package.json 中删除"@react-navigation/core": "react-navigation/core"

    【讨论】:

    • 成功了,非常感谢,我从教程中删除了版本,以为它会下载最后一个版本,但我想我忘了删除'@',有史以来最严重的错误
    猜你喜欢
    • 2017-08-20
    • 1970-01-01
    • 2020-12-16
    • 2021-09-13
    • 2018-05-24
    • 2020-05-30
    • 1970-01-01
    • 2020-02-03
    • 2020-12-29
    相关资源
    最近更新 更多