SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.24k stars 1.01k forks source link

SPFx solution cannot be built with HEFT tooling #9942

Open ltdu opened 3 weeks ago

ltdu commented 3 weeks ago

Target SharePoint environment

SharePoint Online

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

πŸ’₯ SharePoint Framework

Developer environment

Windows

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

Additional environment details

Describe the bug / error

SharePoint Framework YO generator supports --use-heft parameter, which scaffolds solution to use HEFT instead of usual GULP. However, currently building such solution fails in webpack step:

 ---- build started ----
[build:clean] Deleted 0 files and 6 folders
[build:set-browserslist-ignore-old-data-env-var] Setting environment variable BROWSERSLIST_IGNORE_OLD_DATA=1
[build:sass] Generating sass typings...
[build:sass] Generated sass typings
[build:typescript] Using TypeScript version 5.3.3
[build:lint] Using ESLint version 8.57.0
[build:typescript] Copied 10 folders or files and linked 0 files
[build:webpack] Using Webpack version 5.88.2
[build:webpack] Running Webpack compilation
[build:webpack] Error: lib/webparts/helloWorld/HelloWorldWebPart.module.scss:1:0 - Module parse failed: Unexpected character '@' (1:0)
[build:webpack] You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
[build:webpack] > @import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
[build:webpack] |
[build:webpack] | .helloWorld {
 ---- build encountered an error (7.131s) ----
-------------------- Failed (7.14s) --------------------
Encountered 1 error
  [build:webpack] lib/webparts/helloWorld/HelloWorldWebPart.module.scss:1:0 - Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> @import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
|
| .helloWorld {
 ELIFECYCLE  Command failed with exit code 1.

As far as I can tell, problem originates in @microsoft/spfx-heft-plugins package. There is webpackConfigurationPlugin plugin which seems to be responsible for providing required configuration, including webpack loaders. I could find CSS loaders, but configuration seems broken:

// @microsoft\spfx-heft-plugins\lib\plugins\webpackConfigurationPlugin\WebpackConfigurationGenerator.js (L:293)
{
    ...exports.COMMON_RULE_OPTIONS,
    use: moduleScssCssLoaders,
    test: /\.module\.scss\.css$/i
},
{
    ...exports.COMMON_RULE_OPTIONS,
    use: cssLoaders,
    test: /(?<!\.module(\.scss?))\.css$/
},

Steps to reproduce

  1. Create new SPFx web part solution with HEFT support
    yo @microsoft/sharepoint --use-heft
  2. (Optional) Add TypeScript@5.3.3, because otherwise newer version maybe picked up which is not supported by used tools
    npm install typescript@5.3.3 --save-dev --save-exact
  3. Build
    npm run build

Expected behavior

Solution is built successfully

stevebeauge commented 1 day ago

@ltdu: this know for a while. I opened an issue 2 years later #9073 for the same issue, as some other did : https://github.com/SharePoint/sp-dev-docs/issues?q=is%3Aissue+heft+is%3Aopen

I don't think MS is willing to fix this. The spfx build chain is built on top of an incredible complex stack of outdated tools and I guess they're stuck into this stack. Hopefully they will move to a simpler toolchain eventually. They open sourced part of the stack: https://github.com/microsoft/spfx-gulp-tools/issues but obviously (only 3 issues and zero documentation) it did not draw attention it would deserve.

That said, heft is getting quite old, suffer from very long build time and an inexisting community ecosystem compared to more modern tools like turborepo or nx. Maybe you should consider moving out from heft?

On our side we worked sucessfully with nx as build orchestrator and tsup (with a bunch of config) to build shared packages, if it can help