property shorthand usage for animations cause errors in production build #17347
Labels
area: @ngtools/webpack
freq1: low
Only reported by a handful of users who observe it rarely
severity5: regression
type: bug/fix
Milestone
🐞 Bug report
Command (mark with an
x
)Is this a regression?
Yes
Our code ran without problem with
--prod
build flag in angular 7.But now it fails with the same flag in angular 9 with ivy enabled.
Description
We have some shared
animations
definitions like this:animations.ts
the animations are defined in a separate file
animations.ts
. And then it's referenced like this:Those codes look good to me and they works in
Angular 7
. Now withAngular 9
, the production build will throw runtime error:I have found 3 ways to workaround it:
"enableIvy": false,
"optimization": false,
in production configuration (aot
andbuildOptimizer
can still betrue
)property shorthand
foranimations
property, just change toanimations: animations
also fixes the problem.We went with option 3 but it looks confusing why valid typescript code doesn't work and the linter even tell me to use
property shorthand
. It's fine to be a compilation error but unacceptable to be a runtime error only.🔬 Minimal Reproduction
npm run build
to create production buildhttp-server dist/angular9-ext -p 4200
You should see some error messages in the console.
optimization
fromtrue
to false inangular.json
line43
2
to4
Now it loads without problem.
optimization
fromfalse
totrue
2
to4
Now you should see the problem again
src/app/notlazy/notlazycomp/notlazycomp.component.ts
, change line 8 fromanimations,
toanimations: animations,
2
to4
Now it loads without problem.
Turn off ivy also fix the problem but I have a lazy load route in the repo so it may not work. By the way, this problem also breaks the lazy loading if there is the same
animations
property shorthand usage in the lazy loaded module.🔥 Exception or Error
🌍 Your Environment
Anything else relevant?
N/A
The text was updated successfully, but these errors were encountered: