首页 > 解决方案 > 模块构建错误,指出“if”是 postcss-loader index.js 文件中的未知词

问题描述

我一直在努力将 css 依赖项加载到我的 Vue.js webpack 模板中,并以为我终于弄明白了——突然它开始抛出以 postcss-loader 的 index.js 文件为中心的编译失败错误。

这是错误消息:

Failed to compile.

./node_modules/css-loader!./node_modules/vue-style-loader!./node_modules/css-loader??ref--7-1!./node_modules/postcss-loader/lib??ref--7-2!./node_modules/bootstrap/dist/css/bootstrap.min.css
Module build failed: Unknown word (5:1)

  3 | // load the styles
  4 | var content = require("!!../../../css-loader/index.js??ref--7-1!../../../postcss-loader/lib/index.js??ref--7-2!./bootstrap.min.css");
> 5 | if(typeof content === 'string') content = [[module.id, content, '']];
    | ^
  6 | if(content.locals) module.exports = content.locals;
  7 | // add the styles to the DOM
  8 | var update = require("!../../../vue-style-loader/lib/addStylesClient.js")("57f69085", content, false, {});

 @ ./node_modules/bootstrap/dist/css/bootstrap.min.css 2:14-196 21:1-42:3 22:19-201
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

从我的 webpack.base.config 中(将 postcss-loader 添加到混合中没有任何作用,所以我再次将其删除):

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

从我的 main.js 文件中:

import Vue from 'vue'
import App from './App'
import Test from './components/test'
import Test1 from './components/test1'
import router from './router'
import bootstrap from 'bootstrap'
import 'bootstrap/dist/css/bootstrap.min.css'

每当我尝试通过路径(无论是相对路径还是绝对路径)导入 CSS 依赖项时,都会引发此错误。只是使用import 'bootstrap'没有任何效果——它仍然编译,但样式也不起作用。

标签: javascripthtmlcsswebpackpostcss-loader

解决方案


推荐阅读