npm run dev 报错如下:
ERROR in ./src/app.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: E:\demo\react\my-app\src\app.js: Unexpected token (5:7)
3 | import MainRoute from './router/route.js';
4 |
> 5 | render(<MainRoute/>, document.getElementById('app'));
| ^
at Parser._raise (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:746:17)
at Parser.raiseWithData (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:739:17)
at Parser.raise (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:733:17)
at Parser.unexpected (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:8807:16)
at Parser.parseExprAtom (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:10130:20)
at Parser.parseExprSubscripts (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:9656:23)
at Parser.parseMaybeUnary (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:9636:21)
at Parser.parseExprOps (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:9506:23)
at Parser.parseMaybeConditional (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:9479:23)
at Parser.parseMaybeAssign (E:\demo\react\my-app\node_modules\@babel\parser\lib\index.js:9434:21)
Child HtmlWebpackCompiler:
1 asset
Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0
[./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html] 444 bytes {HtmlWebpackPlugin_0} [built]
i 「wdm」: Failed to compile.
babel必要插件已经安装:
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"@babel/preset-react": "^7.10.1",
"babel-loader": "^8.1.0",
后来发现是忘记了配置.babelrc文件:
{
"presets": [
"@babel/env", "@babel/react"
]
}
网友评论