Sass "legacy JS API" Deprecation - Fix in CI
Dart Sass deprecated the legacy render/renderSync JS API in favor of compile/compileString. When a build runs warnings-as-errors, the deprecation notice fails CI.
What this error means
The build prints Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0 and, under strict settings, exits non-zero.
sass
Deprecation Warning [legacy-js-api]: The legacy JS API is deprecated and
will be removed in Dart Sass 2.0.0.
More info: https://sass-lang.com/d/legacy-js-apiCommon causes
Old sass-loader pinning the legacy API
sass-loader before v14 calls the deprecated render API. The warning surfaces through the loader, not your code.
Direct render()/renderSync() usage
A custom build script calls sass.render() instead of the modern sass.compile().
How to fix it
Upgrade sass-loader and select the modern API
- Upgrade sass-loader to a version that defaults to the modern API.
- Set
api: 'modern'explicitly if needed.
webpack.config.js
// webpack.config.js (sass-loader options)
{ loader: 'sass-loader', options: { api: 'modern', implementation: require('sass') } }Migrate custom scripts to compile()
- Replace
render/renderSyncwithcompile/compileString.
build.js
const sass = require('sass');
const result = sass.compile('src/styles/main.scss');
fs.writeFileSync('dist/main.css', result.css);How to prevent it
- Track Sass deprecation channels and migrate before the 2.0 removal.
- Keep sass-loader and sass on supported, compatible versions.
Related guides
Sass "Undefined variable" - Fix in CIFix "SassError: Undefined variable" in CI - a variable used before it is declared, or a module-scoped variabl…
node-sass Not Supported - Migrate to dart-sass in CIFix node-sass build failures in CI - node-sass is deprecated and breaks on newer Node versions; replace it wi…
PostCSS "Cannot find module 'postcss'" - Fix in CIFix "Cannot find module 'postcss'" in CI - postcss is a missing peer dependency of your loader or plugin, or…