react-native - 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>
);
}
}
文件夹截图:
解决方案
您正在尝试导入位于同一文件夹中的名为“LoginScreen”的文件。但是您的文件在/components
目录中。
将您的导入更改为:
import MainNavigator from './components/LoginScreen';
一个点是表示当前目录,这就是你想要的。两个点表示父目录。
推荐阅读
- cpanel - yum 运行良好,但在服务器上安装 cpanel 后,yum 无法执行任何操作
- c# - C#接收UDP数据
- 3d - 单击时为 3d 模型创建链接的提示
- java - 如何从 uid Firebase 数据库中获取电子邮件地址?
- java - 过滤字符串输出/提取一个键值对
- java - “错误:解析时到达文件末尾”
- sas - SAS 如果宏内的条件未按预期工作
- azure - 将在 Azure 上托管的 asp.net 中的环境变量引用的 JSON 文件的存储位置
- linux - 应用程序只看到双处理器机器上可用线程的一半
- hyperledger-fabric - 无法启动或升级 BNA