Skip to content

@microsoft/spfx-web-build-rig unnecessarily generates lib-commonjs folder in SPFx projects #10671

@StfBauer

Description

@StfBauer

Environment

  • Target SharePoint environment: SharePoint Online
  • Development model: SharePoint Framework (SPFx 1.22.2)
  • Developer environment: macOS
  • Node.js: v22.14.0
  • Rig package: @microsoft/spfx-web-build-rig 1.22.2

Describe the bug / error

The default rig package @microsoft/spfx-web-build-rig (v1.22.2) generates a lib-commonjs folder during the build of SPFx web part projects. Since SPFx projects are bundled by webpack for browser delivery, the CommonJS module output is never consumed and serves no purpose.

Three configurations in the rig cause this:

  1. additionalModuleKindsToEmit in the rig's config/typescript.json instructs the Heft TypeScript plugin to emit a second CommonJS build into lib-commonjs, in addition to the primary ESNext output in lib/.

  2. The copy-javascript task in the rig's config/heft.json copies .js source files from src/ to both ./lib and ./lib-commonjs.

  3. cssOutputFolders in the rig's config/sass.json emits compiled CSS to both ["lib", "lib-commonjs"].

The lib-commonjs output is not referenced anywhere in the SPFx webpack pipeline — only the lib/ folder (ESNext modules) is consumed by webpack. This results in unnecessary build time and disk usage for every SPFx project.

Workaround

Projects can override the rig configuration at the project level. Note that Heft's config extends uses append as the default array merge strategy, so setting an array to [] does not override the parent — you must use null to delete inherited array values.

  1. Set "additionalModuleKindsToEmit": null in config/typescript.json to delete the inherited CommonJS emit
  2. Create a project-level config/heft.json (full copy from the rig) and change the copy-javascript task's destinationFolders from ["./lib", "./lib-commonjs"] to ["./lib"]
  3. Replace config/sass.json with a standalone config (no extends) that sets "cssOutputFolders": ["lib"]

Steps to reproduce

  1. Scaffold a new SPFx 1.22.2 project using yo @microsoft/sharepoint
  2. Run npx heft build --clean
  3. Observe that both lib/ and lib-commonjs/ folders are created in the project root

Expected behavior

Only the lib/ folder (ESNext modules) should be generated, as this is the only output consumed by the webpack bundling step. The lib-commonjs folder should not be created for SPFx web part projects.

Metadata

Metadata

Assignees

Labels

area:spfxCategory: SharePoint Framework (not extensions related)sharepoint-developer-supportsharepoint-developer-support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions