首页 > 解决方案 > React-Native App:找不到“.js”文件路径

问题描述

React-native 应用程序找不到我的“.js”文件路径,我不知道为什么。我尝试了几种方法,例如:

1- '../components/LoginScreen' 2- './LoginScreen' 3- './LoginScreen.js'

但同样的结果。

如果有人可以帮助我,这是错误:

Looking for JS files in
   C:\Users\<User>\reactnewapp

Loading dependency graph, done.
 DELTA  [android, dev] ..\..\../index.js ▓▓▓▓▓▓▓▓▓▓▓░░░░░ 70.6% (526/626)::ffff:127.0.0.1 - - [08/Jun/2019:16:39:15 +0000] "GET /index.delta?platform=android&dev=true&minify=false HTTP/1.1" 500 - "-" "okhttp/3.12.1"
error: bundling failed: Error: Unable to resolve module `./LoginScreen` from `C:\Users\<User>\reactnewapp\App.js`: The module `./LoginScreen` could not be found from `C:\Users\<User>\reactnewapp\App.js`. Indeed, none of these files exist:
  * `C:\Users\<User>\reactnewapp\LoginScreen(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`

即使我输入了“./”,它也没有为我提供路径。

应用程序.js:

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Button} from 'react-native';
import MainNavigator from './LoginScreen';


export default class App extends Component {
  render() {
    return (

      <React.Fragment>
      <MainNavigator/>
      </React.Fragment>
    );
  }
}

文件夹截图:

在此处输入图像描述

在此处输入图像描述

标签: react-native

解决方案


您正在尝试导入位于同一文件夹中的名为“LoginScreen”的文件。但是您的文件在/components目录中。

将您的导入更改为:

import MainNavigator from './components/LoginScreen';

一个点是表示当前目录,这就是你想要的。两个点表示父目录。


推荐阅读