Angular-cli: ES2015 + emitDecoratorMetadata causes Cannot access before intialization

Created on 13 Jul 2019  路  4Comments  路  Source: angular/angular-cli

馃悶 bug report

Affected Package

@angular/compiler

Is this a regression?

No, but this is more relevant now because angular-cli permits ES2015 targets.

Description

When targeting ES2015, emitDecoratorMetadata causes a ReferenceError.

馃敩 Minimal Reproduction

https://github.com/pauldraper/angular-decorator-metadata

ng serve

Load in browser.

馃敟 Exception or Error

main.js:98 Uncaught ReferenceError: Cannot access 'AppService' before initialization
    at Module../src/app.component.ts (main.js:98)
    at __webpack_require__ (runtime.js:80)
    at Module../src/app.module.ts (main.js:123)
    at __webpack_require__ (runtime.js:80)
    at Module../src/main.ts (main.js:157)
    at __webpack_require__ (runtime.js:80)
    at Object.0 (main.js:174)
    at __webpack_require__ (runtime.js:80)
    at checkDeferredModules (runtime.js:46)
    at Array.webpackJsonpCallback [as push] (runtime.js:33)

馃實 Your Environment

Angular Version:

Angular 8.1.1

Anything else relevant?

Removing emitDecoratorMetadata, or targeting es5 fixes the problem.

ngtoolwebpack low regression bufix

Most helpful comment

Maybe it would be good to check for that when upgrading angular, or mention it in the docs? This just took me quiet a bit to figure out after upgrading from angular 7 -> 8

All 4 comments

Hi, is there a reason why you need emitDecoratorMetadata to be true?

By the way @pauldraper, love your repo.

This TypeScript option has a fundamental design limitation with ES2015+ code and is best avoided when targeting such output. As such this is an issue with TypeScript itself and not Angular.

Angular 8+ no longer requires the option. It was also previously only required for JIT mode which is typically only used in development.

Maybe it would be good to check for that when upgrading angular, or mention it in the docs? This just took me quiet a bit to figure out after upgrading from angular 7 -> 8

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rajjejosefsson picture rajjejosefsson  路  3Comments

gotschmarcel picture gotschmarcel  路  3Comments

sysmat picture sysmat  路  3Comments

purushottamjha picture purushottamjha  路  3Comments

donaldallen picture donaldallen  路  3Comments