[英]React You may need an appropriate loader to handle this file type
I'm working on an existing project - when I command npm start
the error is - 我正在处理一个现有项目-当我命令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.
this is my webpack.config.js : 这是我的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: './'
}
};
I've solved it by adding include: __dirname + /app/,
but then I got the same error but now its about the ./src/index.js file I simply want to launch it on chrome 我已经通过添加包括来解决了这个问题: __dirname + /app/,
但是我遇到了同样的错误,但是现在它关于./src/index.js文件,我只是想在chrome上启动它
Remove exclude: /node_modules/
from the loader config. 从加载程序配置中删除exclude: /node_modules/
。
Looks like a package you are using isn't compiled down to es5, so you need to tell Webpack to use babel on that file as well. 看起来您正在使用的软件包尚未编译到es5,因此您需要告诉Webpack在该文件上也使用babel。 Ideally you should only allow babel to build that one package. 理想情况下,您只应允许babel构建该软件包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.