最近,当我编译我的scss文件时,我得到一个错误。错误信息如下:
Browserslist: canius -lite已经过时。请运行下一个命令npm update canius -lite browserslist
首先,正如消息所说,我运行npm update canius -lite browserslist,但它没有解决这个问题。
我删除了整个node_modules目录并重新安装,我也通过npm update更新了整个文件夹,但没有一个解决了这个问题。
我还重新安装了autoprefixer和browserslist,但没有一个解决问题。
如果我移除
"options": {
"autoPrefix": "> 1%"
}
从我的编译配置。Json,一切都很好,这意味着它可能与autoprefixer有关。另外,我手动将包版本更改为包上的最新版本。Json和重新安装,但没有运气。
简单、安全的解决方案
来自@Alexandr Nil的答案是安全的,对我来说很有效。我写的是一个完整的答案,因为很容易忽略他的评论。
npm --depth 20 update --save caniuse-lite browserslist
这很好,因为:
There is no deletion of package-lock.json. Deleting that would leave you vulnerable to many packages getting upgraded with breaking changes, and you have a much bigger headache than you had before!
It is easy to understand exactly what it is doing, because it is explicit and very limited on what is to be updated.
It avoids the very large depth of 99 or 9999 which will work on some projects and systems, but not on others. If you have limited the depth to too small a number, it will not break anything. You can increase the depth and try again, until the project compiles successfully. I don't know whether I actually needed 20, or could have managed with a smaller depth, such as 5 or 10. But with a depth of 20 took less than a minute to run.
It is quick and easy!
感谢@Zbyszek建议添加“——save”选项。是的,——depth目前已弃用,但我认为他们会用其他东西取代它,而不是完全删除它,所以现在这似乎是破坏性最小的方法。