我正在研究现有项目 -
当我命令npm start
时,错误是 -
Module parse failed: React/node_modules/react-switch-button/src/react-switch-button.jsx Unexpected token (31:8)
You may need an appropriate loader to handle this file type.
这是我的webpack.config.js:
module.exports = {
entry: [
'./src/index.js'
],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/, //before I added "include" the loading errer
//was about react-switch-button.jsx but compiled index.js
include: __dirname + /app/,// after adding this, can't build index.js (previus error fixed)
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-1']
}
}]
},
resolve: {
extensions: ['.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
};
我已经通过添加include:__dirname + /app/,
解决了这个问题,但后来我得到了同样的错误,但是现在关于./src/index.js文件
我只想在chrome上启动它
答案 0 :(得分:0)
从加载程序配置中删除exclude: /node_modules/
。
看起来你正在使用的软件包没有编译成es5,所以你需要告诉Webpack在该文件上使用babel。理想情况下,您应该只允许babel构建那个包。