Skip to content

🐞 Multi-issue problem with SASS aka SASS-dart - Yarn / NPM workspace configuration #8916

@StfBauer

Description

@StfBauer

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

None

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • [] other (enter in the "Additional environment details" area below)

Additional environment details

  • SPFx version: >1.16.1
  • Node.js version: v16.15.1
  • NPM / Yarn workspace - deprecation of Learna

Describe the bug / error

SPFx has a multi-problem issue with the rush stack and some of the implemented components.

SASS which is now using sass-dart have some issues on how it handles CSS files in general.

Issue 1: tilda use in SASS files

@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';

The ~ before the npm package is wrong because it is only required for direct use of style loader in webpack. In the case of SPFx, all SASS files get compiled into a standalone CSS. Therefore it should not be necessary. Webpack is not involved in loading the SASS file. Instead, the CSS gets picked up automatically from the lib folder.

Issue 2: @import deprecation

With the release of SASS Module System, the @import statement got deprecated by 1 October 2021. In July 2022, it was decided that its support should last longer.

In future, this should not be in any new web part project.

Issue 3:

With the deprecations of @import in SASS files, the correct way to write the same statement shown in issue 1 should get changed to from:

@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';

To this:

@use 'sass:meta'; // import sass:meta module

@include.load-css('~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss'); // load styles from node_modules

This causes the following problems:

~ is incorrect to use in a SASS file, and SASS does not know how to resolve it. It's a webpack feature, but before the involvement of webpack, the style gets generated into the lib folder, which gets picked up by a standard web part css-loader.

One might change tend to change the loading path to:

@use 'sass:meta'; // import sass:meta module

@include.load-css('@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss'); // load styles from node_modules

Without the Tilda, SASS cannot result in the node_modules folder too.

@use 'sass:meta'; // import sass:meta module

@include.load-css('node_modules/@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss'); // load styles from node_modules

Also, do not work because the rush-stack sass task needs to know how to resolve from the project's current location of the node_modules folder.

To solve it, one can do the following.

@use 'sass:meta'; // import sass:meta module

@include.load-css('../../../node_modules/@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss'); // load styles from node_modules

A path to the represented node_modules folder works, but more on that in issues 4 and 5.

Issue 4: Finding the Module

While working with other NextJS, ReactJS and even custom setups, we project there need to be greater loading styles and modules resolution.

In this regard, SPFx is special, indicating a general rush-stack issue when handling SASS files.

The documentation on the module system in SASS states the following on finding the module.

Issue 5: Npm / Yarn workspace - aka Monorepo support

Yarn, as well as npm, have meanwhile an out-of-the-box support for mono repos. However, this base structural change is not supported by SPFx, at least regarding Sass Loading.

I created a sample project that demonstrates what this looks like.

SPFx

In YARN/NPM workspace, none of the modules gets installed inside the project. Instead, the live one level higher outside of the SPFx project.

Typescript can handle this scenario well, but random errors are also attached. Mostly finding the tsconfig file.

** Issue 5a: Cannot find existing CSS **

Let's not involve the new way of sass:meta into style loading into this a simple load of:

@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';

This result in the following error message:

Screenshot 2023-04-24 at 13 46 00

Issue 5b: Cannot find existing CSS

@import '@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';

This result in the following error message:

Screenshot 2023-04-24 at 13 47 49

Issue 5c: Cannot find existing CSS with adjusted CSS link

@import '../../../../@node_modules/@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';;

This result in the following error message:

Screenshot 2023-04-24 at 13 49 53

Issue 6: rush-stack as an option for mono-repos

Developers could subscribe to rust-stack, but the level of abstraction from common project configurations and the deep dependencies, are less safe and future-proof as a solution.

Yarn/npm workspaces keep it plain and simple and work properly together with around 99% of npm packages in the ecosystem.

Steps to reproduce

Checkout project and readme - https://github.com/StfBauer/spfx-workspace

Expected behavior

Proper implementation of SASS.
Proper support for standards such as npm or yarn components.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:spfxCategory: SharePoint Framework (not extensions related)type:archive-old-issueIssues which are closed as tool old for active worktype:bug-suspectedSuspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions