3

Getting this error message on the build of a brand new project just created from Angular:

ERROR in node_modules/@ngrx/store/src/ng2.d.ts(1,10): error TS2305: Module '"../../../@angular/core/core"' has no exported member 'OpaqueToken'.

I did a bunch of searching and found some issues that were not my problem. Here's a few:

1) Module '"node_modules/@angular/core/core"' has no exported member 'OpaqueToken', not using flex-layout

2) Why error in Angular 5 as : has no exported member 'OpaqueToken'.?, no flex-layout, no agm, other issues angular 5 specific.

3) Angular - Module has no exported member 'OpaqueToken' Error, tried the upgrade of ngrx to latest to no effect.

This is a simple app that uses an http request and places the result in a store and then reads that result from a store.

I am not using OpaqueToken directly. Here is my package.json dep section:

  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "@ngrx/core": "github:ngrx/core",
    "@ngrx/store": "github:ngrx/store",
    "core-js": "^2.5.4",
    "cors": "^2.8.5",
    "ngrx": "^2.0.1",
    "rxjs": "^6.4.0",
    "rxjs-compat": "^6.4.0",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.1",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

Any ideas what's incompatible? I'm still pretty new to Angular and it seems like too often, just creating a new app from Angular results in having to fix dependencies.

Thom
  • 14,013
  • 25
  • 105
  • 185

2 Answers2

3

I'm not sure what exactly github:ngrx/store resolves to but it looks like the latest "stable" version (what I get when I go to https://github.com/ngrx/store) is 2.X and according to the package.json in ngrx/store the 2.X version is only compatible with Angular 2.X and Angular 4.X and you are using Angular 7.X.

There is a 4.X version of ngrx/store which appears to target Angular 8.X so maybe you should try that one?

Also, this happens a bit with Angular because components will often list Angular as a peer dependency (for pretty good reasons). This means, even though you have an invalid version of Angular, you only get a warning, not an error at install time.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Pace
  • 41,875
  • 13
  • 113
  • 156
  • That did it, thanks. I wonder why it installed such a decrepit version of ngrx/store. I changed it to: "@ngrx/store": "^4.1.1", – Thom Apr 08 '19 at 20:49
  • Ah, it appears there was a name change of some kind. The NPM module `@ngrx/store` for versions after 2.X are stored in the Github repo: https://github.com/ngrx/platform – Pace Apr 08 '19 at 20:51
1

Checking the angular documentation I've not found OpaqueToken. I think it was deprecated time before and now removed from @angular/core. Exactly InjectionToken is supported by angular following documentation.

InjectionToken

Creates a token that can be used in a DI Provider.

The solution is to replace OpaqueToken with InjectionToken.

P.S. You can pay your attention on NgProbeToken also (it very depends on your needs):

NgProbeToken

A token for third-party components that can register themselves with NgProbe.
Sergii
  • 7,044
  • 14
  • 58
  • 116