Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Dart Sass warns that the legacy JS API will be removed

ErrorThe legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

Short answer

The warning means a tool in your build still calls Dart Sass through its old render or renderSync functions. In Vite, set css.preprocessorOptions.scss.api to modern-compiler, or upgrade to Vite 6, which uses the modern API by default. Silencing it is only a temporary step.

  • Applies to Vite 5.4 to 7, sass 1.79 or newer, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check the Vite and Sass versions, because the fix depends on whether Vite already uses the modern API.

    npm ls vite sass sass-embedded
  2. 2Match what you see, then jump to its fix

    1. 1The warning appears when Vite compiles a .scss or .sass fileVite older than 6 is still using the legacy APIFix
    2. 2Vite is on 6 or newer, but the warning remainsAnother tool in the chain calls the legacy functionsFix

What does the error look like?

  • The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.
  • Warning appears on every build after updating sass to 1.79.0 or newer

Cause 1 of 2

Vite older than 6 is still using the legacy API

1Check

Vite 6 uses the modern API by default, so an older Vite from 5.4 onward is the likely caller.

npm ls vite

2Fix

Upgrade Vite. If you cannot yet, set the api option on Sass in the Vite config, which exists from Vite 5.4.

// vite.config.ts
export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: { api: 'modern-compiler' },
    },
  },
})

3Verify

Start the dev server or build and read the output for the warning.

npx vite build

Confirmed by sass-lang.com

Did this fix it?

Cause 2 of 2

Another tool in the chain calls the legacy functions

1Check

Plugins, test runners and older loaders may call render or renderSync themselves. The deprecation page says to check the tool's own docs or issue tracker for modern API support.

npm ls sass-loader sass node-sass

2Fix

Upgrade the named tool. For webpack, sass-loader is set to the modern API with its api option.

// webpack sass-loader options
{ api: 'modern-compiler' }

3Verify

Run the build again and search the output for legacy-js-api.

npm run build 2>&1 | grep -i legacy

Confirmed by sass-lang.com

Did this fix it?

How do I stop it coming back?

  • Keep Vite and sass on current releases so the modern API is the default.
  • Act on the warning before Dart Sass 2.0.0, which removes the legacy API.
  • Install sass-embedded if you want the best compile speed, as the Vite docs recommend.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.