如何解决Webpack无法构建,因为CssSyntaxError
我正在尝试运行内置的webpack-dev-server,但是每次都会失败,并显示以下错误:
ERROR in ./src/style.css (./node_modules/css-loader/dist/cjs.js!./node_modules/style-loader/dist/cjs.js!./node_modules/css-loader/dist/cjs.js!./src/style.css)
Module build Failed (from ./node_modules/css-loader/dist/cjs.js):
CssSyntaxError
(1:1) UnkNown word
> 1 | var api = require("!../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js");
| ^
2 | var content = require("!!../node_modules/css-loader/dist/cjs.js!./style.css");
3 |
我的webpack.dev.js看起来像这样:
const path = require('path');
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common,{
entry: './src/index.js',mode: 'development',devtool: 'inline-source-map',optimization: {
usedExports: true,},output: {
filename: 'bundle.js',path: path.resolve(__dirname,'dist'),module: {
rules: [
{
test: /\.css$/,use: [
'style-loader','css-loader',],{
test: /\.(png|svg|jpg|gif)$/,use: [
'file-loader',{
test: /\.m?js$/,exclude: /(node_modules|bower_components)/,use: {
loader: 'babel-loader',options: {
presets: ['@babel/preset-env']
}
}
},});
在我的index.js中使用它时出现错误:
import './style.css';
许多解决方案都建议使用样式加载器和css-loader的顺序,但据我所知,顺序正确。我在做什么错了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。