javascript - 我自己的组件的导入在 react native 项目中失败
<p><p>我有文件夹 <code>TestApp</code> 我在其中创建了我的 reactnative 测试应用程序,因此索引文件位于 <code>TestApp/index.ios.js</code>,我有在另一个路径 <code>TestApp/UIComponents/StartScreen/StartScreen.jsx</code> 中声明的组件。
当我尝试在 <code>index.ios.js</code> 文件中导入组件 <code>StartScreen</code> 时,它会给出错误:</p>
<blockquote>
<p>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</p>
</blockquote>
<p>StartScreen.jsx 内容:</p>
<pre><code>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;
</code></pre>
<p>index.ios.js 内容:</p>
<pre><code>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);
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>尝试在您的导入中不使用 .jsx 扩展名。</p></p>
<p style="font-size: 20px;">关于javascript - 我自己的组件的导入在 reactnative 项目中失败,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39955105/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39955105/
</a>
</p>
页:
[1]