尝试得到react-router (v4.0.0)和react-hot loader (3.0.0-beta.6)很好地发挥,但在浏览器控制台得到以下错误:

Warning: React.createElement: type is invalid -- expected a string
(for built-in components) or a class/function (for composite
components) but got: undefined. You likely forgot to export your
component from the file it's defined in.

index.js:

import React from 'react';
import ReactDom from 'react-dom';
import routes from './routes.js';
require('jquery');
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.min.js';
import './css/main.css';

const renderApp = (appRoutes) => {
    ReactDom.render(appRoutes, document.getElementById('root'));
};

renderApp( routes() );

routes.js:

import React from 'react';
import { AppContainer } from 'react-hot-loader';
import { Router, Route, browserHistory, IndexRoute } from 'react-router';
import store from './store/store.js';
import { Provider } from 'react-redux';
import App from './containers/App.jsx';
import Products from './containers/shop/Products.jsx';
import Basket from './containers/shop/Basket.jsx';

const routes = () => (

    <AppContainer>
        <Provider store={store}>
            <Router history={browserHistory}>
                <Route path="/" component={App}>
                    <IndexRoute component={Products} />
                    <Route path="/basket" component={Basket} />
                </Route>
            </Router>
        </Provider>
    </AppContainer>

);

export default routes;

当前回答

这并不是一个与进出口直接相关的问题。在我的例子中,我是在父元素中呈现子元素,并且子元素有jsx element / tag,它被使用但没有导入。我导入并使用它,然后它解决了这个问题。所以问题是在jsx元素里面的子元素,而不是导出子元素本身。

其他回答

我也得到了这个错误。

我用的是:

从'react-dom'导入

费克斯是这样做的:

import {ReactDOM} from 'react-dom';

如果在测试组件时出现此错误,请确保每个子组件在单独运行时都能正确呈现,如果其中一个子组件依赖于外部资源来呈现,请尝试使用jest或任何其他mock库来模拟它:

示例:

jest.mock('pathToChildComponent', () => 'mock-child-component')

我得到了完全相同的错误,做这个代替:

npm install react-router@next 
react-router-dom@next
npm install --save history
// @flow

import React from 'react';
import { styleLocal } from './styles';
import {
  View,
  Text,
  TextInput,
  Image,
} from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';

export default React.forwardRef((props, ref) => {
const { onSeachClick, onChangeTextSearch , ...otherProps } = props;

  return (
        <View style={styleLocal.sectionStyle}>
        <TouchableOpacity onPress={onSeachClick}>
            <Image                              
                    source={require('../../assets/imgs/search.png')}
                    style={styleLocal.imageStyle} />
                </TouchableOpacity>
            <TextInput
                style={{ flex: 1, fontSize: 18 }}
                placeholder="Search Here"
                underlineColorAndroid="transparent"
                onChangeText={(text) => { onChangeTextSearch(text) }}
            />
        </View>
  );
});
 import IGPSSearch from '../../components/IGPSSearch';
<Search onSeachClick={onSeachClick} onChangeTextSearch= {onChangeTextSearch}> </Search>

这并不是一个与进出口直接相关的问题。在我的例子中,我是在父元素中呈现子元素,并且子元素有jsx element / tag,它被使用但没有导入。我导入并使用它,然后它解决了这个问题。所以问题是在jsx元素里面的子元素,而不是导出子元素本身。