Skip to content

Error checking of @use/@forward ... with... is overly strict #2601

@arikorn

Description

@arikorn

Sass does not allow a previously-loaded module to be loaded later using a with clause. I.e. the following is illegal:

// bad.scss

@use "module1";
// the following is not allowed:
@use 'module1' with ( $white: #bbb);

However, when numerous interdependent modules are loaded from a single @use call, such as when loading the popular framework, CoreUI, the Sass error-checking algorithm can lead to spurious errors because even modules that are not affected by the overriding variables are flagged as if they were called with a with clause. See Issue #2598 for several simplified examples.
Just to illustrate the magnitude of the issue, one might load CoreUI, for example, with a few variables overridden:

//Top-level
@use '@coreui/coreui/scss/coreui' with ( $white: #bbb);

This loads the following file (shown in part):

// @coreui/coreui/scss/coreui.scss
@forward "variables";
@forward "variables-dark";
@forward "functions";
@forward "mixins";
....  // loads around 50 files, some of which load even more modules

In this example, only the file '_variables.scss' will have a variable overridden by the top-level call. The remaining files are completely unaffected and do not need to be treated as if they are being loaded with a with clause. Currently, however, Error: This module was already loaded, so it can't be configured using "with". errors can be generated despite the fact the the with was a no-op for those files.

A much better approach would be to only flag files that actually have variables overridden. I will submit a PR shortly, which demonstrates this idea.

Note: As a side-effect this also improves error-reporting when the cause of the error is due to having specified a non-existent variable in the with clause. See examples in Issue #2598

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions