[英]Django/React - You may need an appropriate loader to handle this file type
[英]React You may need an appropriate loader to handle this file type
我正在處理一個現有項目-當我命令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: './'
}
};
我已經通過添加包括來解決了這個問題: __dirname + /app/,
但是我遇到了同樣的錯誤,但是現在它關於./src/index.js文件,我只是想在chrome上啟動它
從加載程序配置中刪除exclude: /node_modules/
。
看起來您正在使用的軟件包尚未編譯到es5,因此您需要告訴Webpack在該文件上也使用babel。 理想情況下,您只應允許babel構建該軟件包。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.