npm install -D sass-loader node-sass Vue.js 2021

20

你好,我需要设置Vue.js的SASS。我运行的环境是:

  • Node.js - 15.7.0
  • Vue.js - @vue/cli 4.5.11

在运行以下命令时,控制台出现了以下错误信息:

npm install -D sass-loader node-sass
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: webpack@3.12.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"2 || 3 || 4" from babel-loader@7.1.5
npm ERR!   node_modules/babel-loader
npm ERR!     dev babel-loader@"^7.1.1" from the root project
npm ERR!   peer webpack@"^3.1.0" from extract-text-webpack-plugin@3.0.2
npm ERR!   node_modules/extract-text-webpack-plugin
npm ERR!     dev extract-text-webpack-plugin@"^3.0.0" from the root project
npm ERR!   8 more (file-loader, friendly-errors-webpack-plugin, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! dev sass-loader@"*" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: webpack@5.18.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.36.0 || ^5.0.0" from sass-loader@10.1.1
npm ERR!   node_modules/sass-loader
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See C:\Users\marko\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\marko\AppData\Local\npm-cache\_logs\2021-01-28T16_11_07_342Z-debug.log

请将答案标记为已接受。 - Beerswiller
5个回答

56

今天我遇到了同样的问题。请尝试安装sass-loader v10.0.5版本:

npm install -D sass-loader@10.0.5 node-sass

2
这个可行!不过我们需要根据机器上安装的node版本安装相应的node-sass版本,具体请参考答案https://dev59.com/UFIG5IYBdhLWcg3whwmc#64833083。 - Pavan J

14

事实上,在Vue CLI文档中有关于这个问题的说明:

在使用webpack 4(Vue CLI 4的默认版本)时,您需要确保您的加载器与它兼容。否则您将会收到有关冲突的peer依赖项的错误提示。在这种情况下,您可以使用仍然与webpack 4兼容的旧版本的加载器。

npm install -D sass-loader@^10 sass


1
这是对我有效的一个。希望这个有更多的点,因为Vue CLI文档似乎已经解决了它。 - Kosi
1
这对我也起作用了。 - Igor

4

虽然此链接可能回答问题,但最好在此处包括答案的基本部分并提供参考链接。仅包含链接的答案可能会在链接页面更改时变得无效。 - M123

2

我通过运行npm install --force命令来解决这个bug。


1

你尝试过使用sass代替node-sass吗?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接