Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production build breaks in rc.11 & 12 #16808

Closed
1 of 15 tasks
tonivj5 opened this issue Jan 31, 2020 · 8 comments · Fixed by #16822
Closed
1 of 15 tasks

Production build breaks in rc.11 & 12 #16808

tonivj5 opened this issue Jan 31, 2020 · 8 comments · Fixed by #16822

Comments

@tonivj5
Copy link

tonivj5 commented Jan 31, 2020

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: rc.10

Description

Production build breaks in rc11 and 12, if I disable optimization in angular-cli.json it goes away. It builds in rc10.

🔬 Minimal Reproduction

I have tried to reproduce it using ng new but the build doesn't emit the same metadata (design:type)

🔥 Exception or Error

image
image


main-es2015.429909d094036241356a.js:6 Uncaught ReferenceError: Observable is not defined
    at main-es2015.429909d094036241356a.js:6
    at Object.6djU (main-es2015.429909d094036241356a.js:6)
    at i (runtime-es2015.4f2dc2db4ea44dd7357a.js:1)
    at Module.zUnb (main-es2015.429909d094036241356a.js:10)
    at i (runtime-es2015.4f2dc2db4ea44dd7357a.js:1)
    at Object.0 (main-es2015.429909d094036241356a.js:6)
    at i (runtime-es2015.4f2dc2db4ea44dd7357a.js:1)
    at t (runtime-es2015.4f2dc2db4ea44dd7357a.js:1)
    at Array.r [as push] (runtime-es2015.4f2dc2db4ea44dd7357a.js:1)
    at main-es2015.429909d094036241356a.js:1

If I disable optimization it works, and Observable is imported from webpack imports instead of as a global variable.
image

🌍 Your Environment


Angular CLI: 9.0.0-rc.12
Node: 13.7.0
OS: linux x64

Angular: 9.0.0-rc.11
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-rc.12
@angular-devkit/build-angular     0.900.0-rc.12
@angular-devkit/build-optimizer   0.900.0-rc.12
@angular-devkit/build-webpack     0.900.0-rc.12
@angular-devkit/core              8.3.24
@angular-devkit/schematics        8.3.24
@angular/cdk                      8.2.3
@angular/cli                      9.0.0-rc.12
@angular/language-service         9.0.0-rc.12
@ngtools/webpack                  9.0.0-rc.12
@schematics/angular               9.0.0-rc.12
@schematics/update                0.900.0-rc.12
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2
    
Done in 0.44s.



Anything else relevant?

@mallen
Copy link

mallen commented Jan 31, 2020

Same issue here - works with optimization disabled

image

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jan 31, 2020

Hi, we’d need some more details to determine from where the regression came;

  1. Can you update Angular FW and CLI/Build-Angular individually and confirm which update causes the issue?

  2. Can you kindly share the one of the classes that is causing the error?

@alan-agius4 alan-agius4 added the needs: more info Reporter must clarify the issue label Jan 31, 2020
@mallen
Copy link

mallen commented Jan 31, 2020

Hi,

Updating individually gives the following results

  • Angular FW rc.10 and CLI/Build-Angular rc.10 works
  • Angular FW rc.11 and CLI/Build-Angular rc.10 works
  • Angular FW rc.11 and CLI/Build-Angular rc.11 fails

image

or with --source-map

image

Possibly @Select from ngxs is causing the issue

Class is

import { Component, Input, OnInit } from '@angular/core';
import { Select, Store } from '@ngxs/store';
import { AppState } from '../app.state';
import { Observable, throwError } from 'rxjs';
import { MenuItem, ParentMenuItem, PlanMenuItem, StandardMenuItem } from '../menu/menu-item';
import { RemovePlanMenuItem } from '../menu/menu.actions';
import { catchError, debounceTime, first, take } from 'rxjs/operators';
import { ContextState } from '../shared/services/context.state';
import { User } from '../shared/user';
import { ContextService } from '../shared/services/context.service';
import { BackgroundType, SettingsService } from '../settings/settings.service';
import { environment } from '../../environments/environment';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Meta } from '@angular/platform-browser';

@Component({
               selector: 'app-navigation',
               templateUrl: './navigation.component.html',
               styleUrls: ['./navigation.component.scss']
           })
export class NavigationComponent implements OnInit {
    @Select(AppState.standardMenuItems) standardMenuItems$: Observable<StandardMenuItem[]>;
    @Select(AppState.parentMenuItems) parentMenuItems$: Observable<ParentMenuItem[]>;
    @Select(AppState.planMenuItems) planMenuItems$: Observable<PlanMenuItem[]>;
    user: User;
    logoSource = 'assets/images/logo_dark.svg';
    @Input() title: string;
    logoutDisabled = false;
    showThemeMenu = false;
    private logoutUrl: string;

    constructor(private store: Store,
                public context: ContextService,
                private settingsService: SettingsService,
                private http: HttpClient,
                private meta: Meta) {
    }

    ngOnInit() {
        this.settingsService.backgroundType$
            .subscribe((bt: BackgroundType) => {
                this.logoSource = bt === 'dark' ? 'assets/images/logo_dark.svg' : 'assets/images/logo_light.svg';
            });

        this.store.select(ContextState.user)
            .pipe(first(user => !!user))
            .subscribe((user => {
                    this.user = user;
                    this.settingsService.setTheme(user, this.settingsService.getThemeFromLocalStorage(user));
            }));

        this.logoutUrl = this.meta.getTag('name=_casLogoutUrl').content;

        if (Storage) {
            this.showThemeMenu = true;
        }
    }

    close(item: MenuItem) {
        if (item instanceof PlanMenuItem) {
            return this.store.dispatch(new RemovePlanMenuItem(item.id));
        }
    }

    logOutClick() {
    }
}

@lVlyke
Copy link

lVlyke commented Feb 1, 2020

Hi,

I'm seeing the same issue on my end with @angular-devkit/build-angular rc.11 and rc.12. I maintain the @lithiumjs/angular library, which is decorator-based like NGXS. I maintain an example app for the library that also makes use of NGXS. I'm seeing the same behavior when running ng serve --prod with @angular-devkit/build-angular rc.12:

Annotation 2020-01-31 181918

The issue appears to happen with @Select from NGXS, and decorators like @StateEmitter and @EventSource from Lithium. As mentioned, setting optimization: false fixes the problem, but is not ideal of course. After enabling sourcemaps, I can see the error happens in my SessionUtils service on the following line:

Annotation 2020-01-31 190754

Branch 4.0.0 of my example app project, which uses @angular-devkit/build-angular rc.10, works fine with ng serve --prod. I created another branch which simply updates the devkit version to rc.12, and that causes the above build issue with ng serve --prod.

Hopefully this helps. Thanks.

@clydin
Copy link
Member

clydin commented Feb 1, 2020

It appears that the common element is that all the projects have the emitDecoratorMetadata TypeScript option enabled. This option has not been required by Angular since version 8.0.4 and newly created projects no longer contain the option. Unless a third-party library or the application code specifically require the presence of the option, it can be safely removed. The need for this option is generally uncommon. Also of note is that the option generates code (more details) that has the potential to cause runtime errors with certain source code constructs.
However, for the cases where the option is required, a fix is currently being investigated.

@lVlyke
Copy link

lVlyke commented Feb 1, 2020

@clydin Interesting, thanks for the info. Removing the use of ES7 reflection and emitDecoratorMetadata from the project does indeed resolve the issue with rc.12.

@alan-agius4 alan-agius4 added this to the v9-blockers milestone Feb 3, 2020
@ngbot ngbot bot removed this from the v9-blockers milestone Feb 3, 2020
@alan-agius4 alan-agius4 added area: @ngtools/webpack and removed needs: more info Reporter must clarify the issue labels Feb 3, 2020
@ngbot ngbot bot added this to the needsTriage milestone Feb 3, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Feb 3, 2020
@alan-agius4 alan-agius4 modified the milestones: Backlog, v9-blockers Feb 3, 2020
@alan-agius4 alan-agius4 self-assigned this Feb 3, 2020
@Timebutt
Copy link

Timebutt commented Feb 4, 2020

Wow thanks guys, removing emitDecoratorMetadata = true from my tsconfig.json fixed the issue for me too! I was looking everywhere to try and fix the broken build until finding this issue 🙌. I can only imagine plenty of other people will also face this cryptic issue, so the v9-blockers milestone is definitely warranted 💪

mgechev pushed a commit that referenced this issue Feb 4, 2020
…re needed for decorator metadata

When `emitDecoratorMetadata` is set to true we don't elide type references imports that are used for decorated nodes.

Fixes #16808
mgechev pushed a commit that referenced this issue Feb 5, 2020
…re needed for decorator metadata

When `emitDecoratorMetadata` is set to true we don't elide type references imports that are used for decorated nodes.

Fixes #16808
This was referenced Feb 6, 2020
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 7, 2020
ikjelle pushed a commit to ikjelle/angular-cli that referenced this issue Mar 26, 2024
…re needed for decorator metadata

When `emitDecoratorMetadata` is set to true we don't elide type references imports that are used for decorated nodes.

Fixes angular#16808
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.