简体   繁体   English

我正在尝试使用 react-native 进行简单的路由,但我遇到了一些类似这样的错误 Failed building Javascript bundle

[英]I am trying to do simple routing with react-native but I am getting some error like this Failed building Javascript bundle

I created one react native project and started Routing.我创建了一个 react native 项目并开始路由。 In a project I have Pages folder, In this folder I have a Home folder in Home folder I have Home.在一个项目中,我有 Pages 文件夹,在这个文件夹中,我在 Home 文件夹中有一个 Home 文件夹,我有 Home。 j's, and I have another folder in Pages that is About in that I have About.js. j 的,并且我在 Pages 中有另一个文件夹,它是 About,因为我有 About.js。 These all are pages.这些都是页面。

I have another folder that is Components, In that I have Navbar folder in that I have Navbar.js我有另一个文件夹,即 Components,其中有 Navbar 文件夹,其中有 Navbar.js

I Imported this Home to Navbar.js And I have Imported Navbar to App.js.我将此主页导入到 Navbar.js 并且我已将导航栏导入到 App.js。 Now I am getting error like this, Unable to resolve "./Pages/Home/Home" from "Components/Navbar/Navbar.js" Failed building JavaScript bundle.现在我收到这样的错误,无法从“Components/Navbar/Navbar.js”解决“./Pages/Home/Home” 无法构建 JavaScript 捆绑包。

In the Pages folder I have a Home folder In that I have Home.js在 Pages 文件夹中,我有一个 Home 文件夹,其中有 Home.js

This Home.js这个 Home.js

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class Home extends Component {
    render() {
        return (
            <View>
                <Text>We have friends</Text>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: '#fff',
      alignItems: 'center',
      justifyContent: 'center',
    },
  });

In the Components Folder I have a Navbar folder in that I have Navbar.js在 Components 文件夹中,我有一个 Navbar 文件夹,其中有 Navbar.js

This is Navbar.js这是 Navbar.js

import { createStackNavigator } from 'react-navigation';
import Home from './Pages/Home/Home';

const Navbar = createStackNavigator({
    Home: { screen: Home },
})

export default Navbar

This is App.js这是 App.js

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Navbar from './Components/Navbar/Navbar'

export default function App() {
  return (
    <Navbar></Navbar>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

I want to resolve the error what I am facing.我想解决我所面临的错误。 If you think still if I am not clear with my doubt or If you don't understand my question please put a comment.如果您仍然认为我不清楚我的疑问或如果您不理解我的问题,请发表评论。

please try something like.../Pages/Home/Home请尝试类似.../Pages/Home/Home

I think you should install react-navigation-stack and import createStackNavigator from there, like:我认为您应该安装react-navigation-stack并从那里导入createStackNavigator ,例如:

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

Namely it has changed the way to import it.即它改变了导入它的方式。 Check the docs检查文档

暂无
暂无

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

相关问题 为什么在尝试分页时出现语法错误(JavaScript)? - Why am I getting syntax error (JavaScript) trying to do a pagination? 我正在构建反应原生应用程序。 在 android 构建中出现一些错误 - I am building react native app . getitng some error in android build 我正在尝试使用React-Native将按钮放置在屏幕底部,我真的很难理解如何在Flex支持下正确地进行操作 - I am trying to place buttons at the bottom of the screen with React-Native and I really struggle to understand how to do it properly with flex support 我正在尝试将此 EJS JavaScript 转换为 React,以用于我正在构建的投资组合网站(初学者) - I am trying to convert this EJS JavaScript to React for a portfolio site I am building (beginner) React Native:尝试从 Cloud Firestore 获取图像时出现错误 - React Native: I am getting error while trying to get image from cloud firestore 为什么在尝试运行新的 React Native 项目时出现错误 - Why am I getting an error when trying to run a new react native project 如何使用 base64 加密在 react-native 中加密密码,我是 react-native 的新手 - how do i encrypt the password in react-native using base64 encryption ,i am new to react-native 尝试在简单对象上执行JSON.parse时出现“意外令牌”错误 - I am getting an “Unexpected token” error when trying to do JSON.parse on a simple object 我正在尝试创建反应应用程序但失败了。 它显示错误 - I am trying to create react app but failed. It show error 我在使用 react native 安装 pod 时遇到错误 - I am getting error in pod install using react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM