-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
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-rig1.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:
-
additionalModuleKindsToEmitin the rig'sconfig/typescript.jsoninstructs the Heft TypeScript plugin to emit a second CommonJS build intolib-commonjs, in addition to the primary ESNext output inlib/. -
The
copy-javascripttask in the rig'sconfig/heft.jsoncopies.jssource files fromsrc/to both./liband./lib-commonjs. -
cssOutputFoldersin the rig'sconfig/sass.jsonemits 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.
- Set
"additionalModuleKindsToEmit": nullinconfig/typescript.jsonto delete the inherited CommonJS emit - Create a project-level
config/heft.json(full copy from the rig) and change thecopy-javascripttask'sdestinationFoldersfrom["./lib", "./lib-commonjs"]to["./lib"] - Replace
config/sass.jsonwith a standalone config (noextends) that sets"cssOutputFolders": ["lib"]
Steps to reproduce
- Scaffold a new SPFx 1.22.2 project using
yo @microsoft/sharepoint - Run
npx heft build --clean - Observe that both
lib/andlib-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.