Javascript 在react本机项目中导入我自己的组件失败
我有一个文件夹Javascript 在react本机项目中导入我自己的组件失败,javascript,ios,react-native,Javascript,Ios,React Native,我有一个文件夹TestApp,我在那里创建了我的react原生测试应用程序,因此索引文件位于TestApp/index.ios.js,我有一个组件在另一个路径TestApp/UIComponents/StartScreen/StartScreen.jsx中声明。 当我试图在index.ios.js文件中导入组件StartScreen时,它给出了错误: 需要未知模块 “/UIComponents/StartScreen/StartScreen.jsx”。如果您确定 如果存在模块,请尝试重新启动打包
TestApp
,我在那里创建了我的react原生测试应用程序,因此索引文件位于TestApp/index.ios.js
,我有一个组件在另一个路径TestApp/UIComponents/StartScreen/StartScreen.jsx
中声明。
当我试图在index.ios.js
文件中导入组件StartScreen
时,它给出了错误:
需要未知模块
“/UIComponents/StartScreen/StartScreen.jsx”。如果您确定
如果存在模块,请尝试重新启动打包机或运行“npm安装”。
未知模块错误
require.js:147 loadModuleImplementation
require.js:88 guardedLoadModule
需要.js:65
_要求
需要.js:49
index.android.js:18 loadModuleImplementation
require.js:122 guardedLoadModule
www.js:58
_要求
require.js:49全局代码
require-0.js:1
StartScreen.jsx内容:
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';
class StartScreen extends Component {
render() {
return (
<View>
<Text>Some text</Text>
</View>
);
}
}
export default StartScreen;
import React,{Component}来自'React';
进口{
样式表,
文本,
看法
}从“反应本机”;
类StartScreen扩展组件{
render(){
返回(
一些文本
);
}
}
导出默认StartScreen;
index.ios.js内容:
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Image,
View,
TextInput,
ScrollView,
ListView
} from 'react-native';
import StartScreen from './UIComponents/StartScreen/StartScreen.jsx';
class VertuoseApp extends Component {
render() {
return (
<StartScreen/>
);
}
}
AppRegistry.registerComponent('Vertuose', () => VertuoseApp);
import React,{Component}来自'React';
进口{
评估学,
样式表,
文本,
形象,,
看法
文本输入,
滚动视图,
列表视图
}从“反应本机”;
从“/UIComponents/StartScreen/StartScreen.jsx”导入StartScreen;
类VertuoseApp扩展了组件{
render(){
返回(
);
}
}
AppRegistry.registerComponent('Vertuose',()=>VertuoseApp);
尝试在导入时不使用.jsx扩展名。@AdrianZghibarta我认为您的文件必须保存在.js而不是.jsx中。“我认为您的文件必须保存在.js而不是.jsx中”,您是对的,非常感谢。