【发布时间】:2018-01-21 23:15:39
【问题描述】:
奇怪的是,React Native 无法解决本地文件导入的错误。
Unable to resolve module `./components/MyComponent" from ".//App.js`: could not resolve `/Users/myusername/Desktop/mylibrary/components/MyComponent' as a file nor as a folder","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]},"type":"bundling_error"}"
mylibrary/App.js:
import React from 'react';
import {
View,
Text,
StyleSheet,
ScrollView,
AsyncStorage,
} from 'react-native';
import MyComponent from './components/MyComponent';
mylibrary/components/MyComponent.jsx:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
export default class MyComponent extends React.Component {
render() {
<View>
{this.props.children}
</View>
}
}
我尝试将文件重命名为小写 (mycomponent.jsx),但没有任何区别。我也试过重启模拟器,重置缓存,也没有用。
【问题讨论】:
-
如果我没记错
import语句默认尝试导入.js文件,尝试将MyComponent.jsx重命名为MyComponent.js
标签: react-native