繁体   English   中英

错误模块解析失败:意外的令牌 - Webpack

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM