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

[Regression] aot compilation breaks enums from other files #13136

Open
jacobfederer opened this Issue Dec 5, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@jacobfederer

jacobfederer commented Dec 5, 2018

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

Node Version: v10.8.0

npm version: 6.4.1

ng version:


    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
   

Angular CLI: 7.1.0
Node: 10.8.0
OS: darwin x64
Angular: 7.1.0
... animations, bazel, cdk, cli, common, compiler, compiler-cli
... core, forms, http, language-service, material
... material-moment-adapter, platform-browser
... platform-browser-dynamic, router, service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.6
@angular-devkit/build-angular     0.11.0
@angular-devkit/build-optimizer   0.10.6
@angular-devkit/build-webpack     0.10.6
@angular-devkit/core              7.0.6
@angular-devkit/schematics        7.0.6
@angular/flex-layout              7.0.0-beta.19
@angular/pwa                      0.10.6
@ngtools/webpack                  7.0.6
@schematics/angular               7.0.6
@schematics/update                0.11.0
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.23.1

Os: MacOSX Mojave

Repro steps

Use enum inside a file like this:

export enum ErrorCode {
    SERVERSIDE_VALIDATION_ERROR_KEY = 'serverside_validation_error',
    ENTITY_NOT_EXISTENT_ERROR_KEY = 'entity_not_existent_error',
    DEPENDENT_ENTITY_ERROR_KEY = 'dependent_entity_error',
    DUPLICATE_ERROR_KEY = 'duplicate_error',
  }

export default class Utils {

Import the enum like this:

import {Component} from '@angular/core';
import Utils, {ErrorCode} from "../utils";

@Component({
  selector: 'adresse',
  templateUrl: './adresse.component.html'
})
export class AdresseComponent {

  constructor() {
  }

  get errorCodes() {
    return ErrorCode
  }
}

Then run: ng build --prod

The issue seems to be related to #10655 but this time setting buildOptimzier and optimisation in angular.json to false does not resolve the issue.

Turning off Ahead of Time compilation seems to help for now.

The log given by the failure

ReferenceError: Can't find variable: ErrorCode
get — main.95f4ea6bc507b9cafd32.js:215914
(anonyme Funktion) — main.95f4ea6bc507b9cafd32.js:215882:4327
checkAndUpdateView — main.95f4ea6bc507b9cafd32.js:70116
callViewAction — main.95f4ea6bc507b9cafd32.js:70357
execComponentViewsAction — main.95f4ea6bc507b9cafd32.js:70299
checkAndUpdateView — main.95f4ea6bc507b9cafd32.js:70122
callViewAction — main.95f4ea6bc507b9cafd32.js:70357

Desired functionality

That it finds the Enums.

@ngbot ngbot bot added this to the needsTriage milestone Dec 5, 2018

@ngbot ngbot bot removed this from the needsTriage milestone Dec 5, 2018

@clydin

This comment has been minimized.

Member

clydin commented Dec 5, 2018

If setting build optimizer to false results in the same error then this does not appear to be related to build optimizer. Can you change the title to reflect that please?

The issue appears to be caused by AOT compilation and the use of the import Utils, {ErrorCode} from "../utils"; statement. The combination of import clauses is causing the problem. If using just import {ErrorCode} from "../utils";, it should work without issue.

Also, a minimal reproduction based on a new project is extremely helpful to properly troubleshoot issues such as these.

@jacobfederer jacobfederer changed the title from [Regression] build optimizer breaks enums from other files to [Regression] aot compilation breaks enums from other files Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment