我是使用Reactjs的初学者,当我运行webpack时出现以下错误:
ERROR in ./src/client/app/index.jsx
Module parse failed: Unexpected token (6:11)
You may need an appropriate loader to handle this file type.
代码:
class App extends React.Component {
render () {
return <p> Hello React!</p>;
} }
我是按照以下网站提供的说明做到的:
以下行将告诉您版本详细信息
"author": "",
"license": "ISC",
"babel-preset-react": "^6.24.1",
"react": "^16.2.0",
"react-dom": "^16.2.0"
"babel-core": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-preset-es2015": "^6.24.1",
"webpack": "^4.0.1",
"webpack-cli": "^2.0.10"
答案 0 :(得分:0)
您关注的指南已经过时了,webpack.config.js
中描述的配置对象现在不同了。
替换:
module : {
loaders : [
{
test : /\.jsx?/,
include : APP_DIR,
loader : 'babel'
}
]
}
... with:
module : {
rules: [{
test : /\.jsx?/,
include : APP_DIR,
use: 'babel-loader'
}]
}
然后,找一个更新的指南:)
或安装较早版本的webpack
。