1

I get the Cannot access 'MyComponent' before initialization error message in the browser.

The ng build ran without errors.

I did a little research about this topic and found suggestions to update my app's tsconfig.base.json file with this setting:

{
  "compilerOptions": {
    "emitDecoratorMetadata": false
  }
}

It's not helped. So added this:

  "annotateForClosureCompiler": {
    "annotateForClosureCompiler": true
  }

Also not helped. So tried to change the target from es2015 to any newer but not solved the problem.

I tried to change these settings on my library too (what contains the component), but isn't helped.

I checked these discussions:

In my case I use 10.1.6 from Angular packages:

{
  "dependencies": {
    "@angular/animations": "^10.1.6",
    "@angular/cdk": "^10.2.5",
    "@angular/common": "^10.1.6",
    "@angular/compiler": "^10.1.6",
    "@angular/core": "^10.1.6",
    "@angular/forms": "^10.1.6",
    "@angular/material": "^10.2.5",
    "@angular/platform-browser": "^10.1.6",
    "@angular/platform-browser-dynamic": "^10.1.6",
    "@angular/router": "^10.1.6",
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1001.3",
    "@angular/cli": "^10.1.7",
    "@angular/compiler-cli": "^10.1.6",
  }
}

Any idea?

1 Answer 1

1

I solved my circular dependency on my library and the error is gone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.