无法解析'文件'或'目录'(反应)

时间:2017-01-16 11:39:28

标签: reactjs import module

尝试从文件夹组件导入新模块,但我遇到了一些错误

我的index.js

import React from 'react'
import {
    render
} from 'react-dom'
import {
    Provider as ReduxProvider
} from 'react-redux'
import {
    Router,
    Route,
    IndexRoute,
    Link,
    Redirect,
    browserHistory
} from 'react-router'


import  App  from './components'



import {
    routerMiddleware
} from 'react-router-redux'

import {
    IntlProvider,
    addLocaleData
} from 'react-intl'
import en from 'react-intl/locale-data/en'
import zh from 'react-intl/locale-data/zh'
addLocaleData([...en, ...zh])


    import {
        createStore,
        compose,
        applyMiddleware
    } from 'redux'
    import Immutable from 'immutable'
    import {
        combineReducers
    } from 'redux-immutable'
    import thunk from 'redux-thunk'
    render((
        <ReduxProvider >
            <IntlProvider locale={'en'}>
              <Router history={browserHistory}>
                <Route path="/" component={App}>



                </Route>
              </Router>
            </IntlProvider>
      </ReduxProvider>
    ), document.getElementById('mount'))

包含组件src / components的文件夹 那里有我的结构

enter image description here

我的App.JS内部文件夹组件

import React from 'react'
import { Link, browserHistory } from 'react-router'

    export default function App({ children }) {
      return (
        <div>
          1
        </div>
      )
    }
    export default App

enter image description here

所以我不明白为什么它没有看到带有组件的目录,我错了?

1 个答案:

答案 0 :(得分:2)

导入目录时,文件解析器将在目录中查找index.js

所以这个导入:

import  App  from './components'

正在寻找要导入的./components/index.js文件。这不会导入App.js

请改为尝试:

import  App  from './components/App'