angular-hybrid: "No provider for UrlService" error since version 3.1.3 (Angular CLI based app in AOT mode)
I’ve got hybrid app based on Angular CLI. When running app in AOT mode (ng serve -o --aot=true) when this piece of code is run:
platformBrowserDynamic().bootstrapModule(AppModule)
.then(platformRef => {
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, ['app'], {strictDi: false});
const url: UrlService = platformRef.injector.get(UrlService);
url.listen();
url.sync();
});
I am getting:
"Unhandled Promise rejection: No provider for UrlService! ; Zone: <root> ; Task: Promise.then ; Value: Error: No provider for UrlService!"
Both AOT/JIT version works fine with version 3.1.2. Version 3.1.3/3.1.4 works only in JIT mode.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 18 (2 by maintainers)
@adamlubek remove ‘uirouter/angular’ and ‘uirouter/angularjs’ in your package.json file, only use ‘uirouter/angular-hybrid’
I found this is the working example : https://github.com/ui-router/sample-app-angular-hybrid/tree/e4b1144d5e3e3451f0f0cc640175bb7055294fdd you can try download and build it
@artaommahe so I changed code from:
to
this compiles indeed but it completely breaks routing, states which were working aren’t recognized anymore
@adamlubek also had this problem, this fixed my issue https://github.com/ui-router/sample-app-angular-hybrid/issues/8#issuecomment-322673416
For anyone coming to this issue looking to resolve the “no provider” errors, make sure that you do not have multiple copies of the
@uirouter/*packages nested in your node_modules directory.One easy way to find out is to run these commands:
For each one, make sure there is only one version of the uirouter packages in the output.
good output
For example, for
@uirouter/coreonly version 6.0.1 is listed in the output:bad output
If there are multiple versions of a uirouter library, the output will look something like this:
Note that versions 6.0.1 and 6.0.3 are both present
note: If you use
yarnpackage manager, the command isyarn why @uirouter/core@adamlubek i use it like so