BrowserAnimationsModule vs NoopAnimationsModule: Angular Material animation retention in production builds
0 reputation · 29 Jan 2021, 17:02 UTC
0 reputation · 29 Jan 2021, 17:02 UTC
Retain MatMenu and MatTooltip animations after an Angular CLI production build while keeping the standard BrowserAnimationsModule import.
angular.json can strip animation triggers, making components appear non‑interactive.BrowserAnimationsModule with NoopAnimationsModule avoids runtime errors but disables all Material animations globally, requiring per‑component opt‑ins.angular.json optimization flags (e.g., scriptsOptimization, stylesOptimization) preserve animation metadata for Material components?NoopAnimationsModule is the root provider?Angular Material components such as MatMenu and MatTooltip retain their animations in a production build as long as the real animation engine is provided at the root injector (i.e., BrowserAnimationsModule in an NgModule app or provideAnimations() in a standalone bootstrap). Replacing that provider with NoopAnimationsModule or provideNoopAnimations() disables all Material animations globally.
BrowserAnimationsModule registers the actual @angular/animations engine via the ANIMATION_MODULE_TYPE token.NoopAnimationsModule registers a no‑op engine that resolves animation triggers instantly, which removes all transitions.scriptsOptimization, stylesOptimization, buildOptimizer) do not selectively strip animation metadata; they only affect code size and dead‑code elimination.If animations disappear after ng build --configuration production, the most common cause is that the real animation provider is absent or has been conditionally swapped for the no‑op provider in the production configuration (e.g., a custom file replacement, a webpack plugin, or an environment‑specific import).
AppModule) or the standalone bootstrap (main.ts) for the import of BrowserAnimationsModule (or call to provideAnimations()). Ensure it is not guarded by an environment check that imports NoopAnimationsModule instead.angular.json uses the default builder (@angular-devkit/build-angular:browser) and that no custom builder or fileReplacements swaps the animation module between dev and prod.*fadeIn trigger on a div). If that works, the build pipeline is preserving animations and the issue is isolated to your component‑level provider configuration.NoopAnimationsModule or missing BrowserAnimationsModule (look for the provider names in the generated main.js).Can you confirm whether your application boots via an NgModule (AppModule) or uses standalone bootstrapApplication, and whether there is any environment‑specific import that conditionally swaps BrowserAnimationsModule for NoopAnimationsModule?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.