“node-sass”用法已弃用,将在未来的主要版本中删除

fat*_*maa 10 angular

当我从 Angular 8升级到11 时,我遇到了这个警告

'node-sass' 用法已弃用,并将在未来的主要版本中删除。要选择退出已弃用的行为并开始使用“sass”,请卸载“node-sass”。

任何人都可以帮助我
在此先感谢

小智 28

尝试将“node-sass”替换为“sass”

npm uninstall node-sass
npm i -S sass
Run Code Online (Sandbox Code Playgroud)


Ahm*_*tah 14

完整的错误信息是

'node-sass' usage is deprecated and will be removed in a future major version. To opt-out of the deprecated behaviour and start using 'sass' uninstall 'node-sass'.

因此,我认为您可以尝试的唯一解决方案是显而易见的,只需卸载 node-sass。

=> 我已经卸载它并尝试过ng serveng build --prod一切正常。

仅供参考,作为一名开发人员,我总是发现这个库node-sass令人头疼,因为它的不兼容错误。我很高兴我们不必再使用它并处理其痛苦的错误。

  • 你的项目中使用sass吗?因为卸载node-sass并且不做任何其他事情是不够的。 (7认同)
  • 是的,先生,我在我的应用程序中使用 scss 文件,并且工作正常。 (2认同)
  • 有趣,谢谢您提供的信息。这对我来说还不够。 (2认同)

小智 6

$ npm uninstall node-sass
Run Code Online (Sandbox Code Playgroud)

这也将修复以下错误。

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/resolve-url-loader/index.js):
Error: resolve-url-loader: CSS error
  source-map information is not available at url() declaration (found orphan CR, try removeCR option)
Run Code Online (Sandbox Code Playgroud)


rob*_*ord 6

您可以将node-sass替换为sass,这是sass的dart版本。

新项目管理

npm uninstall node-sass
npm install sass
Run Code Online (Sandbox Code Playgroud)

yarn remove node-sass
yarn add sass
Run Code Online (Sandbox Code Playgroud)

如果您使用 gulp,请确保使用正确的用法更新您的构建脚本:https://www.npmjs.com/package/gulp-sass