-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
🐞 Bug report
Command (mark with an x)
- new
- build
- serve
- test
- e2e
- generate
- add
- update
- lint
- extract-i18n
- run
- config
- help
- version
- doc
Description
I have a index.ts which imports 2 modules (abstract-control.ts and abstract-control.directive.ts) for side effects, and exports another module (custom-control-status.directive.ts) therefore also acting as a barrel file. custom-control-status.directive.ts is imported through the barrel file (index.ts), therefore I thought index.ts and the 2 modules imported for side effects would be included in the bundle, but they're removed in the tree shaking process.
I tried both of the following:
- specifying
"sideEffects"inpackage.json's:"sideEffects": ["<path>/index.ts", "<path>/abstract-control.ts" and "<path>/abstract-control.directive.ts"]in the app'spackage.json- Add a
package.jsonto the directory and set"sideEffects": ["./index.ts", "./abstract-control.ts" and "./abstract-control.directive.ts"]in it - Add a
package.jsonto the directory and set"sideEffects": truein it
- specifying a rule in Webpack's
module.rulesthat matches every TS file in the directory and setsideEffects: true
Despite that, they are all excluded from the bundle. Could this be an issue with Angular's webpack config or @angular-builders/custom-webpack?
🔬 Minimal Reproduction
Reproduction repository: https://github.com/amitbeck/ng-webpack-sideEffects-repro
Either:
- Run
npm run build(alias forng build --configuration production), or - Run
npm run serve(alias forng serve --configuration production) and access through http://localhost:4200. You should get the following error:TypeError: this.formGroup.controls.text.setWarnings is not a function
abstract-control.ts, abstract-control.directive.ts and index.ts in src/app/utils/forms/ are not included in the bundle.
🌍 Your Environment
Angular CLI: 13.2.6
Node: 16.13.1
Package Manager: npm 8.1.2
OS: darwin x64
Angular: 13.2.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker, upgrade
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1303.1
@angular-devkit/build-angular 13.2.6
@angular-devkit/core 13.3.1
@angular-devkit/schematics 13.2.6
@angular/cdk 13.2.6
@angular/cdk-experimental 13.2.6
@angular/cli 13.2.6
@angular/material 13.2.6
@schematics/angular 13.2.6
rxjs 7.5.5
typescript 4.5.5
Anything else relevant?
Possibly related to #12912 and webpack/webpack#15610.
Also asked a question in SO and asked a Webpack team member for help in webpack/webpack#15610 (comment).