Sass
1. filter: invert(var(--p, 0.9))报错
SassError: $color: --p is not a color.
原因
Sass函数和CSS的新特性存在冲突,Sass的invert函数(用于获取反相色)位于颜色模块,它是这么用的:
color.invert($color, $weight: 100%)
invert($color, $weight: 100%) //=> color
所以filter: invert(var(--p, 0.9))
提示错误为$color: --p is not a color.
。
类似问题的函数还有min、max、grayscale、opacity
等等。
解决方法
借助Sass大小写敏感但CSS不敏感的特性。filter: Invert(var(--p, 0.9))
无法被Sass理解,但这仍是有效的CSS。其他的函数也可以使用类似的方法解决。
When Sass and New CSS Features Collide
2. Error: Node Sass version 6.0.0 is incompatible with ^4.0.0.
环境:node: 16.3.0
网上大多数答案都是卸载node-sass
然后安装node-sass@4.14.1
,但是这个方法在我这里不奏效,因为我的node版本比较高,按照官方要求就必须使用6+的node-sass。
解决方法
查阅了相同问题的issue,找到了解决办法: 在package.json中添加:
"devDependencies": {
"node-sass": "^6.0.0",
"sass-loader": "^12.0.0"
}
然后删除node_modules和yarn.lock文件,重新yarn install
。方法奏效,原因暂时不明。
webpack
1. babel转码报错
es.object.get-own-property-descriptor.js?e439:12 Uncaught TypeError: $ is not a function
at eval (es.object.get-own-property-descriptor.js?e439:12)
at Object../node_modules/core-js/modules/es.object.get-own-property-descriptor.js (vendors-5b14f7ca0710a4a53a28.js:1247)
at __webpack_require__ (index-f0e82474be574b1ce6d8.js:42)
at eval (object-get-own-property-descriptor.js:2)
at Object../node_modules/core-js/internals/object-get-own-property-descriptor.js (vendors-5b14f7ca0710a4a53a28.js:742)
at __webpack_require__ (index-f0e82474be574b1ce6d8.js:42)
at eval (export.js?23e7:2)
at Object../node_modules/core-js/internals/export.js (vendors-5b14f7ca0710a4a53a28.js:380)
at __webpack_require__ (index-f0e82474be574b1ce6d8.js:42)
at eval (es.array.concat.js?99af:2)
webpack配置出现了问题,缺少exclude: /node_modules/
,也就是:
{
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/, // 别漏了这一句
use: {
loader: "babel-loader"
}
}
]
}
}
如果按照官方要求进行配置,是不会出现问题的,但是总会出现一些手抖或者巴拉巴拉的原因。
为什么不配置exclude: /node_modules/
会报错?官方是这么说明的:
exclude-libraries-that-should-not-be-transpiled
core-js和webpack/buildin等三方包已经被编译过了,再编译一遍可能就会出错了,需要把他们排除。
2.Invalid Host header
本地开发使用devServer启动服务器,如果通过域名来访问服务