Undefined selector warning during @extend compilation
0 reputation · 11 Jun 2022, 16:12 UTC
0 reputation · 11 Jun 2022, 16:12 UTC
The @extend directive is designed to allow a selector to inherit rules from another existing selector, merging them into a single rule in the final CSS output. However, the compiler behavior varies when the target selector is not defined within the same stylesheet or is missing from the current scope.
When using @extend, the target selector must be defined prior to the extension call. If the compiler cannot locate the referenced selector, it may trigger a compile warning rather than a hard error, potentially leading to silent failures where styles are not applied to the intended elements.
In modern Sass versions, specifically when utilizing @use for module scoping, the visibility of placeholder selectors (%.example) across different partials is restricted. This creates uncertainty regarding how the compiler handles extensions of placeholders that are defined in a module but not explicitly exported or accessible to the extending file.
@extend?34775 reputation · 11 Jun 2022, 17:28 UTC
The Sass compiler emits an "undefined selector" warning when the selector referenced in @extend cannot be found in the current compilation scope.
Under the modern @use module system, selectors are scoped to their module and must be accessed with the module's namespace (e.g., @extend utils.%button). If the namespace is omitted or the module is not loaded, the target is treated as undefined, triggering the warning. This behavior is the same for placeholder selectors (%.name) and regular class or element selectors.
@use 'path/to/module'; at the top of the file.@extend module-name.%placeholder or @extend module-name .class.@use statement precedes the @extend line; the module system handles ordering automatically, but keep the import before any extension.Are you using the legacy @import syntax or the modern @use/@forward module system? This determines whether the namespace prefix is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.