简体   繁体   English

React Native:“构建 JavaScript 包失败。 无法从“App.js”解析“@react-navigation/stack”

[英]React native: “Failed building JavaScript bundle. Unable to resolve ”@react-navigation/stack“ from ”App.js“”

I am using react-native and I am trying to add navigation to my project.我正在使用 react-native 并且我正在尝试向我的项目添加导航。 When I add this line of code:当我添加这行代码时:

import { createStackNavigator } from "@react-navigation/stack"; , I get this error: ,我得到这个错误:

Failed building JavaScript bundle.
Unable to resolve "@react-navigation/stack" from "App.js"

I tried all the solutions suggested in this stackoverflow link but, none worked for me.我尝试了此stackoverflow 链接中建议的所有解决方案,但没有一个对我有用。 I reinstalled everything using these commands more than once.我不止一次地使用这些命令重新安装了所有东西。

I am using expo.我正在使用 expo。

To use stackNavigator, you should install dependencies separately.要使用 stackNavigator,您应该单独安装依赖项。

After install @react-navigation/native, install @react-navigation/stack:安装@react-navigation/native 后,安装@react-navigation/stack:

npm install @react-navigation/stack

Tutorial says that:教程说:

To use this navigator, ensure that you have @react-navigation/native and its dependencies (follow this guide), then install @react-navigation/stack:要使用此导航器,请确保您拥有 @react-navigation/native 及其依赖项(遵循本指南),然后安装 @react-navigation/stack:

npm install @react-navigation/stack npm 安装@react-navigation/stack

I had the same issue while using expo.我在使用 expo 时遇到了同样的问题。

My solution was just to start expo with the flag to clear the Metro bundler cache我的解决方案是使用标志启动 expo 以清除 Metro 捆绑器缓存

expo start -c

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从“App.js”解析“@react-navigation/stack” - Unable to resolve “@react-navigation/stack” from “App.js” 无法从“App.js”解析“react-navigation-stack” - Unable to resolve “react-navigation-stack” from “App.js” 无法从…/App.js 解析模块“react-navigation”:Haste 模块 map 中不存在模块“react-navigation” - Unable to resolve module 'react-navigation' from …/App.js: Module 'react-navigation' does not exist in the Haste module map 构建 JavaScript 包失败。 无法读取反应本机模块 traverseDependencies.js 上未定义的属性“减少” - Failed building JavaScript bundle. Cannot read property 'reduce' of undefined on react native module traverseDependencies.js 无法从“App.js”解析“react-navigation-drawer” - Unable to resolve “react-navigation-drawer” from “App.js” 无法从 App.js 解析模块 - React Native - Unable to resolve module from App.js - React Native 未能构建 JavaScript 捆绑包。 无法解析模块。/reanimated2 - Failed building JavaScript bundle. Unable to resolve module ./reanimated2 无法从“node_modules\react-navigation-stack\lib\module\navigators\createStackNavigator.js”解析“react-navigation” - Unable to resolve “react-navigation” from “node_modules\react-navigation-stack\lib\module\navigators\createStackNavigator.js” 用于反应导航的Homescreen(App.js)结构 - Homescreen (App.js) structure for react-navigation React Native 程序从“App.js”返回“无法解析”srcscreensComponentsScreenListScreen“ - React Native program returns “Unable to resolve ”srcscreensComponentsScreenListScreen“ from ”App.js"
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM