javascript - 模块构建错误,指出“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'
没有任何效果——它仍然编译,但样式也不起作用。
解决方案
推荐阅读
- mysql - SQL SELECT 来自多个表的列的平均值
- python - 使用“计划”在 Python 中的确定时间仅运行一次计划任务
- r - 如何在 RStudio 中使用正确的箭头而不是 <- 作为赋值运算符?
- java - 如果没有启动 Corda,如何防止 Spring 失败?
- android - 在 Android 上的 Delphi 中获取总内存和可用内存
- sass - CRA - 存储在数据库中的主色
- google-cloud-dataflow - 数据流 Flex Runner 启动时失败
- r - 如果组包含值逻辑 R
- next.js - 带有 next-rewrite 的 next-i18next 不适用于根页面重写路径
- javascript - 使用 zigbee USB CC2531 读取数据