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

AOT build failed with @Inject enum in constructor #8011

Closed
benbenw opened this issue Oct 11, 2017 · 4 comments
Closed

AOT build failed with @Inject enum in constructor #8011

benbenw opened this issue Oct 11, 2017 · 4 comments

Comments

@benbenw
Copy link

benbenw commented Oct 11, 2017

Bug Report or Feature Request (mark with an x)

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

Versions.

@angular/cli: 1.4.5
node: 8.1.4
os: darwin x64
@angular/animations: 4.4.4
@angular/common: 4.4.4
@angular/compiler: 4.4.4
@angular/core: 4.4.4
@angular/forms: 4.4.4
@angular/http: 4.4.4
@angular/platform-browser: 4.4.4
@angular/platform-browser-dynamic: 4.4.4
@angular/router: 4.4.4
@angular/cli: 1.4.5
@angular/compiler-cli: 4.4.4
@angular/language-service: 4.4.4
typescript: 2.3.4

Repro steps.

ng new myNgBug
cd myNgBug
npm install
edit src/app/app.component.ts to add an enum and a constructor

import { Component, Inject } from '@angular/core';

export enum DisplayMode {
  Inventory = 0, Replenishment = 1, Withdrawal = 2
}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';

  constructor( @Inject( DisplayMode ) private displayMode: DisplayMode) { }
}

nb build --prod

The log given by the failure.

Date: 2017-10-11T15:49:06.246Z                                                     
Hash: 93b637bd9e9474fc5a25
Time: 1187ms
chunk {0} styles.d41d8cd98f00b204e980.bundle.css (styles) 0 bytes {3} [initial] [rendered]
chunk {1} polyfills.3bc34265385d52184eab.bundle.js (polyfills) 86 bytes {3} [initial] [rendered]
chunk {2} main.e402deade8b026b7d50e.bundle.js (main) 84 bytes [initial] [rendered]
chunk {3} inline.22b7623ed7c5ac6f9a35.bundle.js (inline) 1.45 kB [entry] [rendered]

ERROR in Error: Internal error: unknown identifier {"Inventory":0,"Replenishment":1,"Withdrawal":2}
    at Object.importExpr$$1 [as importExpr] (/pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:24211:23)
    at tokenExpr ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:18577:39)
    at depDef ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:18588:89)
    at  /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:18568:81
    at Array.map (native)
    at singleProviderDef ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:18568:53)
    at providerDef ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:18476:9)
    at ViewBuilder._visitProviderOrDirective ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:22952:18)
    at ViewBuilder._visitDirective ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:22830:23)
    at  /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:22744:32
    at Array.forEach (native)
    at ViewBuilder._visitElementOrTemplate ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:22734:23)
    at ViewBuilder.visitElement ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:22645:23)
    at ElementAst.visit ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:323:24)
    at visit ( /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:670:37)
    at  /pathtoproject/myNgBug/node_modules/@angular/compiler/bundles/compiler.umd.js:672:42

Desired functionality.

It should build

Mention any other details that might be useful.

the build pass when aot is disabled

@jotatoledo
Copy link

jotatoledo commented Oct 11, 2017

Shouldnt you inject that through a InjectionToken?

@hansl
Copy link
Contributor

hansl commented Oct 11, 2017

Hi @benbenw,

You cannot use a pure type to inject, e.g. an enum or an interface. You will need to use an InjectionToken, as @jotatoledo pointed out. Please follow Angular's documentation for help on how to use tokens.

Please note this is not a problem with the Angular CLI. This error (and further discussions and support) should be moved to github.com/angular/angular.

Closing this as Working As Intended.

@hansl hansl closed this as completed Oct 11, 2017
@benbenw
Copy link
Author

benbenw commented Oct 11, 2017

Sorry for the noise.

But it's misleading as it compiles without aot

@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 Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants