A shared Sass library built on @import and global functions floods consumer builds with Dart Sass deprecation warnings; how do you migrate it to the module system safely?
answer
- read the deprecation id first
- the migrator does the namespacing
- global built-ins move to sass: modules
- an import-only file for old users
- removal waits for Dart Sass 3.0.0
basics
~20 sRun sass-migrator module --migrate-deps on the entry point to turn @import into @use/@forward and global functions into sass: module calls, forward the public API from the index, keep an import-only file for old consumers, and gate CI on deprecations.
solid answer
~40 sRead the warnings first: since Dart Sass 1.80.0, `@import` and global built-ins such as `map-get()` warn (`import`, `global-builtin`), and `/` division has warned since 1.33.0 (`slash-div`). `/` becomes a list separator in Dart Sass 2.0.0; `@import` is removed in 3.0.0, no sooner than two years after 1.80.0. Then let `sass-migrator module --migrate-deps` rewrite the library: it adds namespaces and `@use` rules, turns overridden defaults into `with` clauses and strips `-`/`_` from members used across files; `--forward=all` makes the index forward the public API, and `sass-migrator division` converts `/` to `math.div()`. `darken()` has no module counterpart, so choose `color.adjust()` or `color.scale()` by hand. Ship a `<name>.import.scss` file that forwards with the old prefix for `@import` consumers, release a major version, and fail CI on these deprecations.
code
bash · 11 linesnpm install -g sass-migrator
# @import -> @use/@forward, global built-ins -> sass: modules;
# the files passed forward every public member they used to import
sass-migrator --migrate-deps module --forward=all campus-ui/_index.scss
# remaining / divisions -> math.div()
sass-migrator division campus-ui/*.scss
# CI gate: every deprecation present in Dart Sass 1.80.0 is an error
sass --fatal-deprecation=1.80.0 campus-ui/preview.scss build/preview.cssgo deeper
Recall that Sass @import and functions like map-get() are deprecated in Dart Sass, and that @use with sass: modules such as sass:map replaces them.
Explain what the module migrator changes (namespaces, new @use rules, with clauses, private prefixes) and what replaces / division and the global built-in functions.
Plan the migration so consumers do not break: forward the public API from an index, keep an import-only file for @import users, release a major version, and gate CI on deprecations.
Sequence consumer migrations against the Dart Sass 2.0.0 and 3.0.0 timelines, and decide how long the library supports @import consumers before dropping the import-only file.
## What the warnings are telling you Each Dart Sass deprecation warning carries a **deprecation id**, and the id tells you what to change and how urgent it is. | Deprecation id | Deprecated in | Replace with | When it stops working | |---|---|---|---| | `slash-div` | 1.33.0 | `math.div()` or `calc()` | Dart Sass 2.0.0 treats `/` as a list separator | | `mixed-decls` | 1.77.7 | Declarations before nested rules, or `& { … }` | Obsolete since 1.92.0: output now follows written order | | `legacy-js-api` | 1.79.0 | `compile()` / `compileAsync()` in build tooling | Removed in Dart Sass 2.0.0 | | `import` | 1.80.0 | `@use` and `@forward` | Removed in Dart Sass 3.0.0 | | `global-builtin` | 1.80.0 | `sass:` module functions such as `map.get()` | Removed in Dart Sass 3.0.0 | Dart Sass 3.0.0 will be released no sooner than two years after 1.80.0, so `@import` is not an emergency; `/` division is closer, because Dart Sass 2.0.0 changes what `/` means. The `legacy-js-api` row concerns the build tooling that calls Sass, not the library's stylesheets. ## Step 1: triage without hiding the problem Consumer sites see the library's warnings in their own builds. Two command-line switches help while the fix is in progress, and neither is the fix: - `--quiet-deps` hides deprecation warnings from **dependencies**, meaning any stylesheet loaded transitively through a load path, while keeping warnings from the site's own files. - `--silence-deprecation=import` hides one deprecation id everywhere. Silencing both families needs `import` and `global-builtin`, because they are separate ids. ## Step 2: run the migrators 1. `sass-migrator module --migrate-deps` on the library's entry point rewrites `@import` to the module system. It adds namespaces to member references, adds `@use` rules to files that relied on globals, converts overridden `!default` variables into `with` clauses, strips `-` and `_` from members used across files (they would otherwise become private), and converts nested imports to `meta.load-css()`. It also migrates global built-in calls; `--built-in-only` does only that part. 2. `--forward=all` makes the files you pass `@forward` every public member they used to import, so the index keeps exposing the whole API. `--remove-prefix=campus-` strips the old `campus-` prefixes that `@import` forced on every member. 3. `sass-migrator division` converts `/` used as division into `math.div()`. The migrator must read every dependency, so pass `--load-path` if the build uses one. ## Step 3: shape the public API The index file (`campus-ui/_index.scss`, loaded by `@use "campus-ui"`) becomes the library's API: - `@forward "tokens";` re-exports members as if they were defined in the index. - `show` and `hide` (`@forward "grid" hide old-columns;`) control which members are public. - `as campus-*` adds a prefix to every forwarded member. For consumers not yet migrated, ship an **import-only file** named `<name>.import.scss`. Sass loads it only for `@import`, never for `@use`, so it can `@forward` the module `as campus-*` and keep the old prefixed names working while `@use` users get the clean API. ## Step 4: fix what the migrator cannot decide - **Colour helpers with no module counterpart.** `darken()` and `lighten()` were never added to `sass:color`. `color.adjust($c, $lightness: -10%, $space: hsl)` preserves the old output; `color.scale($c, $lightness: -10%)` is usually the better design but changes colours, so it needs a visual check. - **Nested imports.** `@use` must sit at the top level. Wrapping the nested file's CSS in a mixin and including it is the recommended migration; `meta.load-css()` is the direct translation. - **Mixed declarations.** Since Dart Sass 1.92.0, declarations written after nested rules are emitted in the order written, duplicating the outer selector if needed, as CSS nesting does. Review the rules the `mixed-decls` warning used to flag. ## Step 5: lock it in and release 1. In the library's CI, compile with `--fatal-deprecation=1.80.0`, which turns every deprecation present in 1.80.0 into an error, so `@import`, global built-ins and `/` division cannot creep back. 2. Publish a **major version**: namespaced members and removed prefixes are breaking changes for consumers. 3. Each consuming site then runs its own module migration against the new API, on its own schedule but before Dart Sass 3.0.0.
- A consumer site sees the library's deprecation warnings in its own Dart Sass build. What can it do before the library ships a fix?Compile with `--quiet-deps`, which hides deprecation warnings from stylesheets reached through a load path while still showing warnings from the site's own files. `--silence-deprecation=import` hides one deprecation id everywhere and is a stopgap. Neither changes the schedule: Sass `@import` is removed in Dart Sass 3.0.0.
- Why does `darken()` need a decision rather than a mechanical rename?It was never given a `sass:color` counterpart, because it lowers HSL lightness by a fixed amount, which is rarely the intended effect. `color.adjust($c, $lightness: -10%, $space: hsl)` reproduces the old output exactly; `color.scale($c, $lightness: -10%)` darkens relative to the current lightness and usually looks better, but it changes colours, so it needs a visual check.
- What did Dart Sass 1.92.0 change that can alter a migrated library's output?Declarations written after nested rules are now emitted in the order written, duplicating the outer rule if needed, as CSS nesting does; earlier releases hoisted them above the nested rules. The `mixed-decls` deprecation warning, added in 1.77.7, flagged these spots. Wrapping such declarations in `& { … }` opts older compilers into the new order too.
- Silencing the deprecation warnings is a complete fix for @import.
- @import already stopped compiling in current Dart Sass 1.x releases.
- Every global function has a sass: module equivalent with the same name.
- Find-and-replace @import with @use is enough to migrate a library.
- math.div() divides differently from the old / operator.
Assumes Dart Sass 1.105 (major 1): / division deprecated in 1.33.0, @import and global built-ins in 1.80.0 with removal in Dart Sass 3.0.0, and declarations after nested rules emitted in written order since 1.92.0.