Dart Sass warns that the legacy JS API will be removed
The 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.
Fix it fast
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-embedded2Match what you see, then jump to its fix
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 vite2Fix
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 buildConfirmed by sass-lang.com
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-sass2Fix
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 legacyConfirmed by sass-lang.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix