[英]Error Module parse failed: Unexpected token - Webpack
我在使用 webpack 时遇到问题,刚刚从另一个项目中添加了一个新组件,并且控制台错误在附件中,这是我在webpack.config.js
中的 const 配置:
const config = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['@babel/plugin-transform-runtime', 'react-hot-loader/babel']
}
}
},
{
test: /\.css$/,
use: ['style-loader', 'raw-loader']
}
]
},
plugins: [new HtmlWebpackPlugin({ template: './src/index.html' })]
}
请尝试从您的 `module.rules[0] 配置中删除exclude: /node_modules/,
。
您尝试编译的文件位于node_modules
中,它需要带有@babel/preset-react
babel-loader
来编译它。
您还可以定义正则表达式,例如它将排除除此文件之外的所有 node_modules。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.