Webpack,React,Babel - 无法解析模块

时间:2015-11-10 10:22:46

标签: reactjs webpack babeljs webpack-dev-server

我已经安装了react-hot-loader并在webpack.config.js中引用了该模块。但是,当我尝试运行webpack来编译脚本时,我收到一个错误。

请参阅下面的截图。有人可以告诉问题是什么。仅供参考,我正在使用所有最新的图书馆。

 [1]: http://i.stack.imgur.com/2GCa1.jpg

    /*webpack.config.js
    module.exports = {
devtool: 'eval-source-map',
entry: {
    main: [
        './src/main.js'
    ]
},
output: {
    filename: './public/[name].js'
},
module: {
    loaders: [
        {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: ['react-hot','babel-loader'],
            query: {
                presets: ['es2015', 'react']
            }
        }
    ]
}
}

/*UPDATE*/
Code update
I have added an "s" after loader. It is now giving me the below error.

[2]: http://i.stack.imgur.com/LL1nn.jpg

2 个答案:

答案 0 :(得分:6)

根据您的第二张照片,您可以尝试以下操作:

loaders: [
        {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: ['react-hot'],
        },
        {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: ['babel-loader'],
            query: {
                presets: ['es2015', 'react']
            }
        }
    ]

答案 1 :(得分:1)

我用webpack,babel和react-hot-loader创建了一个启动器。请查看我的配置:https://github.com/skrobek/webpack-react/blob/master/webpack.config.js

和package.json https://github.com/skrobek/webpack-react/blob/master/package.json#L19

随意使用它: - )