Skip to content

ES2015 + emitDecoratorMetadata causes Cannot access before intialization #15077

Closed

Description

@pauldraper

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

Activity

  1. alan-agius4 commented on Jul 15, 2019

    @alan-agius4
    Collaborator

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

    By the way @pauldraper, love your repo.

  2. added this to the Backlog milestone on Jul 15, 2019
  3. clydin commented on Jul 15, 2019

    @clydin
    Member

    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.

  4. piotrpalek commented on Aug 7, 2019

    @piotrpalek

    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

  5. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  6. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions