Rolling back a Dart Sass upgrade after @import deprecation warnings broke the build
0 reputation · 13 Aug 2020, 19:44 UTC
0 reputation · 13 Aug 2020, 19:44 UTC
A project currently compiles with Dart Sass and relies heavily on the legacy @import rule across many partials. Since the 1.80.x line formally deprecated @import in favor of @use/@forward, upgrading to a newer release floods the build with deprecation warnings, and the pipeline may treat warnings as fatal depending on its flags.
The goal is a safe upgrade-and-recovery strategy: move to a current Dart Sass version while keeping a reliable way back if compilation output or behavior changes unexpectedly. Constraints: the codebase is not yet migrated with sass-migrator, some partials depend on @import's global namespace, and the build tool pins Sass via package.json plus a committed lockfile. Sass itself has no built-in downgrade mechanism, so recovery presumably means reverting the pinned version and lockfile together.
Assuming Dart Sass in the 1.8x range, the open questions are:
@import/@use) produce duplicate CSS that survives the downgrade?--fatal-deprecation) determine whether warnings become hard errors, and how can that be verified per build pipeline?35775 reputation · 14 Aug 2020, 01:25 UTC
@import and @use can emit duplicate CSS if the same partial is reached twice – once via the import and once via the module. This only happens when the file is imported directly and also used as a module.sass-migrator against the old 1.8x release is safe; the tool will not apply the semantic changes that newer Sass introduces. However, you still need to review the generated CSS for duplicate rules.--fatal-deprecation. Other flags include --no-deprecation (silence all warnings) and --quiet-deprecation (only show the first warning per file). Verify which flag your CI uses.In package.json, set the Sass dependency back to the previous 1.8x version you were using (e.g., "sass": "^1.80.0").
Restore the corresponding lockfile (package-lock.json or yarn.lock) that was committed before the upgrade. This ensures that npm ci or yarn install --frozen-lockfile installs the exact same patch version.
Run npm ci (or yarn install --frozen-lockfile) to install the old compiler.
Execute your build command locally and confirm that no deprecation warnings appear. A quick sanity check: sass --version should show the 1.8x release.
@import will compile normally with the old Sass. If you later migrate a file to @use, ensure you remove the @import line that was previously there; otherwise the same CSS will be injected twice.@import part is processed first, injecting CSS, and the @use part loads the module without side effects. If the same partial is imported elsewhere via @import, you’ll see duplicate rules in the final CSS.diff -u old.css new.css.# Install the old Sass locally
npm install sass@1.80.0 --save-dev
# Run migrator against the old compiler
npx sass-migrator --dry-run src/**/*.scss
Running it on the 1.8x release avoids the new deprecation logic that could otherwise rewrite imports into forwards automatically.
--fatal-deprecation – turns every deprecation warning into a non‑zero exit code.--no-deprecation – suppresses all deprecation warnings.--quiet-deprecation – shows only the first warning per file.To verify which flag your CI uses, run the exact build command locally and observe the exit status. If the command exits with a non‑zero code when warnings are present, --fatal-deprecation is active or your CI has a --strict wrapper.
Could you confirm whether your continuous‑integration pipeline treats warnings as errors (e.g., via a --strict flag or by using --fatal-deprecation)? Knowing this will determine whether we need to disable that flag or rely on the rollback alone.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.