> 技术文档 > 项目警告 Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0._deprecation warning [legacy-js-api]: the legacy js

项目警告 Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0._deprecation warning [legacy-js-api]: the legacy js


项目警告 Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

1、输入命令pnpm list sass,检查实际的sass版本,发现为sass@1.81.0;

  • 解决方法:
    直接输入命令,安装sass指定版本为sass@1.77.8:
pnpm install sass@1.77.8 -D
  • 其它模块的版本号:
  • node -v: v16.20.0
  • npm -v: 8.19.4
  • pnpm -v: 8.15.9
  • vite: vite@4.5.14
  • sass: sass@1.77.8
  • vue: vue@3.5.13

重新执行pnpm build,进行项目编译打包,发现已经没有了警告warning。

2、如果还有警告问题,解决办法如下:
构建工具 vite.config.js 配置文件修改

import { defineConfig } from \'vite\'import vue from \'@vitejs/plugin-vue\'export default defineConfig({ server: { host: \'0.0.0.0\' }, plugins: [vue()], css: { // CSS 预处理器 preprocessorOptions: { // 定义全局 SCSS 变量 scss: { api: \'modern-compiler\', // \"modern-compiler\" or \"modern\", \"legacy\" silenceDeprecations: [\'legacy-js-api\'], // 重点:解决sass警告问题 javascriptEnabled: true, additionalData: `@use \"@/styles/_variables.scss\" as *;` } } }})

品牌设计公司