ERROR NullInjectorError: R3InjectorError when building a lib and using services who are not providedIn root
See original GitHub issue🐞 bug report
Affected Package
@angular/core
Is this a regression?
Yes, only happens with ivy. If I disable ivy, everything works as expected
"angularCompilerOptions": {
"enableIvy": false
}
Description
We are using ionic-native for our crossplatform apps. So we created some libraries to share code between different apps. If we use ionic-native (which has no providedIn root) we add the providers inside forRoot of a module in the library (1), build the library and add this module from our library in our AppModule (2). If we now using the service from the lib (3), the error occurs on start-up
We created an minimal repo where you can see the issue.
(2) https://github.com/paulstelzer/angular-ionic-issue/blob/master/src/app/app.module.ts
(3) https://github.com/paulstelzer/angular-ionic-issue/blob/master/src/app/app.component.ts
🔬 Minimal Reproduction
Github: https://github.com/paulstelzer/angular-ionic-issue
Nice to know: The “dist” folder is already comitted, so you do not need to build the lib. If you want just run npm run lib:build
,
npm i
ng serve
The app will show the error like mentioned below
🔥 Exception or Error
core.js:6185 ERROR NullInjectorError: R3InjectorError(AppModule)[PlatformService -> Device -> Device -> Device]:
NullInjectorError: No provider for Device!
at NullInjector.get (http://localhost:4200/vendor.js:36155:27)
at R3Injector.get (http://localhost:4200/vendor.js:49871:33)
at R3Injector.get (http://localhost:4200/vendor.js:49871:33)
at R3Injector.get (http://localhost:4200/vendor.js:49871:33)
at injectInjectorOnly (http://localhost:4200/vendor.js:36010:33)
at ɵɵinject (http://localhost:4200/vendor.js:36020:57)
at Object.PlatformService_Factory [as factory] (http://localhost:4200/main.js:103:356)
at R3Injector.hydrate (http://localhost:4200/vendor.js:50107:63)
at R3Injector.get (http://localhost:4200/vendor.js:49859:33)
at NgModuleRef$1.get (http://localhost:4200/vendor.js:67203:33)
🌍 Your Environment
Angular Version:
Angular CLI: 9.0.7
Node: 10.16.0
OS: win32 x64
Angular: 9.0.7
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.900.7
@angular-devkit/build-angular 0.900.7
@angular-devkit/build-ng-packagr 0.900.7
@angular-devkit/build-optimizer 0.900.7
@angular-devkit/build-webpack 0.900.7
@angular-devkit/core 9.0.7
@angular-devkit/schematics 9.0.7
@ngtools/webpack 9.0.7
@schematics/angular 9.0.7
@schematics/update 0.900.7
ng-packagr 9.0.3
rxjs 6.5.4
typescript 3.7.5
webpack 4.41.2
Anything else relevant? We building the library with ng-packagr! This can also be a bug of ionic-native!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
@mlc-mlapis I wasn’t aware of that issue but it looks to be the same as #35759 for which I commented on how to make it work: https://github.com/angular/angular/issues/35759#issuecomment-601444856.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.