core: Cannot read property 'when' of undefined
I’m running a project that uses angular hybrid with the following versions:
- “angular”: “1.8.0”
- “@angular/core”: “10.0.3”
- “@uirouter/angular-hybrid”: “11.0.2”
- “@uirouter/angular”: “7.0.0”
- “@uirouter/angularjs”: “1.0.28” …
When executing unit tests I’m getting “Cannot read property ‘when’ of undefined” in most of the tests (karma with chai and mocha). I tried to debug and see that is pointing to node_modules/@uirouter/core/lib-esm/resolve/resolvable.js
this.promise = this.resolved ? services.$q.when(this.data) : undefined; ( https://github.com/ui-router/core/blob/master/src/resolve/resolvable.ts#L84 )
If I guard against this.resolved the error is gone
this.promise = this.resolved && services ? services.$q.when(this.data) : undefined;
Could you suggest in which cases services can be undefined and if this can be fixed on master? Should I create a pull request for it?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 19 (4 by maintainers)
I had the same problem.
Output:
As of npm cli v8.3.0 (2021-12-09) this can be solved using the
overridesfield ofpackage.jsonFirst add an explicit install of
@uirouter/core. I used version6.0.8because I am not sure if the latest version6.0.9is supported on@uirouter/angularjs.Your
package.jsonshould now have this line added to it.Next specify that this installed version of
@uirouter/coreshould be used by the dependent libraries. Manually update yourpackage.jsonand add/update theoverridessection.Run your install one more time.
And finally check the dependent versions one last time.
@eydrian or @mansevmann did you ever solve this?
for angularjs/angular-hybrid when uirouter/core@6.0.8 is explicitly installed, exactly this error will happen! Only works with @uirouter/core@6.0.7
I also think this can be caused by multiple copies of
@uirouterlibraries in yournode_modulesTry running:
or
Look for any uirouter packages with two different versions listed.