webpack 错误 Module build failed (from ./node_modules/css-loader/dist/cjs.js): CssSyntaxError

错误

npm run build

> webpack_test@1.0.0 build /home/q/www/webpack_test
> webpack

Hash: e5a0c99f86239b7fee98
Version: webpack 4.39.3
Time: 345ms
Built at: 08/30/2019 7:13:18 PM
 1 asset
Entrypoint app = app.bundle.js
[1] ./src/index.js 313 bytes {0} [built]
[2] (webpack)/buildin/global.js 472 bytes {0} [built]
[3] (webpack)/buildin/module.js 497 bytes {0} [built]
[4] ./src/style.css 593 bytes {0} [built] [failed] [1 error]
    + 1 hidden module

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in ./src/style.css
Module build failed (from ./node_modules/css-loader/dist/cjs.js):
CssSyntaxError

(1:1) Unknown word

> 1 | var content = require("!!./style.css");
    | ^
  2 | 
  3 | if (typeof content === 'string') {

 @ ./src/index.js 2:0-21
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! webpack_test@1.0.0 build: `webpack`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the webpack_test@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

查看你的webpack.config.js 的css配置如下:

rules: [
      {
        test: /\.css$/,
        use: [
           'css-loader',
           'style-loader',
    
        ]
      }
    ]

更改为 必须style-loader在前边,css-loader在后边

rules: [
      {
        test: /\.css$/,
        use: [
      	   'style-loader',
           'css-loader',
        ]
      }
    ]

再次npm run build 就成功了!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值