我有文件夹 TestApp
我在其中创建了我的 react native 测试应用程序,因此索引文件位于 TestApp/index.ios.js
,我有在另一个路径 TestApp/UIComponents/StartScreen/StartScreen.jsx
中声明的组件。
当我尝试在 index.ios.js
文件中导入组件 StartScreen
时,它会给出错误:
Requiring unknown module "./UIComponents/StartScreen/StartScreen.jsx".If you are sure the module is there, try restarting the packager or running "npm install". unknownModuleError require.js:147 loadModuleImplementation require.js:88 guardedLoadModule require.js:65 _require require.js:49 index.android.js:18 loadModuleImplementation require.js:122 guardedLoadModule require.js:58 _require require.js:49 global code 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;
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);
尝试在您的导入中不使用 .jsx 扩展名。
关于javascript - 我自己的组件的导入在 react native 项目中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39955105/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |