React.js模块解析失败:

时间:2018-10-03 20:18:45

标签: reactjs webpack module

我不明白为什么会出现这样的错误,我是一个初学者,所以请有人能帮助我解决这个问题,并告诉我为什么它会给我带来错误

ERROR in ./src/index.js 7:16
Module parse failed: Unexpected token (7:16)
You may need an appropriate loader to handle this file type.
| import registerServiceWorker from './registerServiceWorker';
| 
> ReactDOM.render(<App />, document.getElementById('app'));
| registerServiceWorker();
| 

这是我的webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.export = {

    entry: '.src/index.js',
    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'index_bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader'

                }
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html'
        })
    ]
}

这是我的index.js

    import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('app'));
registerServiceWorker();

0 个答案:

没有答案