close

[Solved] Angular: 7.2.1 ES6 class ReferenceError : Cannot access ‘X’ before initialization

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error in Angular. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How To Solve Angular: 7.2.1 ES6 class ReferenceError : Cannot access ‘X’ before initialization Error ?

  1. How To Solve Angular: 7.2.1 ES6 class ReferenceError : Cannot access 'X' before initialization Error?

    To Solve Angular: 7.2.1 ES6 class ReferenceError : Cannot access 'X' before initialization Error The solution is to set "emitDecoratorMetadata": false in your tsconfig.json file.

  2. Angular: 7.2.1 ES6 class ReferenceError : Cannot access 'X' before initialization

    To Solve Angular: 7.2.1 ES6 class ReferenceError : Cannot access 'X' before initialization Error The solution is to set "emitDecoratorMetadata": false in your tsconfig.json file.

Solution 1

The solution is to set "emitDecoratorMetadata": false in your tsconfig.json file.

Solution 2

I was getting this error due to a circular dependency, like

  • A injected with B
  • B injected with C
  • C injected with A

Removing the circular dependecy fixed this error.

Solution 3

Note that this error can also be caused by defining two public @Injectable classes within the same .ts file.

I’ve tripped over this more than once when I’m just prototyping stuff locally (especially when refactoring one service into multiple).

Setting emitDecoratorMetadata: false does fix this situation as well, but in case you’re in a hurry to fix something or don’t want to fiddle with thetsconfig.json file on a large project – it’s useful to know that you might be able to fix it by just copying one of the classes into a new file.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment