-
Notifications
You must be signed in to change notification settings - Fork 27k
Description
Which @angular/* package(s) are the source of the bug?
compiler-cli, compiler
Is this a regression?
No
Description
When libraries are built using esbuild (e.g. some rc versions of ng-packagr before the change was reverted) the built packages are unusable in webpack builds (verified with ng serve and ng test)
Causes ng-packagr/ng-packagr#2850 (which is closed because the move to esbuild was reverted)
Please provide a link to a minimal reproduction of the bug
ng-packagr/ng-packagr#2850 (comment)
Please provide the exception or error you saw
ReferenceError: Cannot access '_c1' before initialization
at 3347 (main.js:163526:23)
at __webpack_require__ (runtime.js:23:41)
at 25429 (main.js:6695:71)
at __webpack_require__ (runtime.js:23:41)
at 76311 (main.js:6539:92)
at __webpack_require__ (runtime.js:23:41)
at __webpack_exec__ (main.js:203398:48)
at main.js:203399:229
at __webpack_require__.O (runtime.js:57:23)
at main.js:203400:56
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 18.0.3
Node: 20.11.0
Package Manager: yarn 3.3.1
OS: darwin arm64
Angular: 18.0.2
... cdk, common, compiler, compiler-cli, core, elements, forms
... localize, platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1800.3
@angular-devkit/build-angular 18.0.3
@angular-devkit/core 18.0.3
@angular-devkit/schematics 18.0.3
@angular/cli 18.0.3
@schematics/angular 18.0.3
rxjs 7.8.1
typescript 5.4.5
zone.js 0.14.7
Anything else?
Note the line numbers in the main.js file:


(excuse the partial screenshots, the codebase is not public)
The const _cX statements are inserted way below where they're used.
This appears to be caused by esbuild not hoisting imports in its output. If I update the built "FESM" file and move all import statements to the top of the file, everything works and the _cX constants are defined before they're used.