为什么导入在本机反应中不起作用? [英] Why is importing not working in react native?
问题描述
我正在尝试将我的第二个文件导入我的项目的 App.js.我收到错误开发服务器返回响应错误代码:500".基本上是说无法从App.js"解析MainFile".
I am trying to import my second file into App.js for my project. I am getting the error "The development server returned response error code: 500". Basically saying "Unable to resolve "MainFile" from "App.js".
为什么会这样?我相信这是正确的,但出于某种原因,这个 bugfest 说该文件不存在.第一个代码是我的 App.js 文件,第二个是我尝试导入的代码.
Why is this happening? I believe it is correct but for some reason this bugfest saying that the file doesn't exist. First code is my App.js file and the second one is the code i am trying to import.
https://gyazo.com/6911c477f9c9e8149370571ca49a0b9f>
https://gyazo.com/6911c477f9c9e8149370571ca49a0b9f
https://gyazo.com/73f0079bc6a2640877bcc30fa1e609ec
import React from 'react';
import MainFile from './components/MainFile';
export default class App extends React.Component{
render() {
return(
<MainFile />
);
}
}
<小时>
import React from 'react';
import {StyleSheet, Text, View, TextInput, ScrollView, TouchableOpacity} from 'react-native';
export default class MainFile extends React.Component{
render(){
return(
<View style={styles.container}>
<Text>Testing</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
},
});
推荐答案
- 删除 node_modules 文件夹
- edit package json : react-native version to "55.4" or "55.2" andbabel-preset-react-native 为4.0.0"(如果你的版本不同尝试使用最新的或降级).
- 运行 npm install 或 yarn install 命令
- 大功告成
来源:Github
这篇关于为什么导入在本机反应中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!