Skip to content

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

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

Closed
jacobfederer opened this issue Dec 5, 2018 · 3 comments
Closed

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

jacobfederer opened this issue Dec 5, 2018 · 3 comments
Labels
freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix

Comments

@jacobfederer
Copy link

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
Copy link
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.

@clydin clydin added type: bug/fix needs: investigation Requires some digging to determine if action is needed freq1: low Only reported by a handful of users who observe it rarely severity3: broken labels Dec 5, 2018
@jacobfederer jacobfederer changed the title [Regression] build optimizer breaks enums from other files [Regression] aot compilation breaks enums from other files Dec 6, 2018
@clydin
Copy link
Member

clydin commented Oct 22, 2020

Thank you for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

@clydin clydin closed this as completed Oct 22, 2020
@clydin clydin removed the needs: investigation Requires some digging to determine if action is needed label Oct 22, 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 Nov 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

No branches or pull requests

3 participants