I'm trying to package a module X with dependencies to Y using ng-pacakgr. X and Y have services and components.
App/module structure is :
- ModuleX imports ModuleY
- X.forRoot() provides ServiceY.
- ServiceY is used in AppModule and ModuleX.
- AppModule imports both modules X.forRoot() and Y.forRoot().
AppModule - ModuleY - ServiceY - ModuleX - ServiceX - ModuleY - ServiceY
Packaging ModuleX with ng-packagr tells me this :
No name was provided for external module 'Y' in options.globals – guessing 'Y'
OK
Running the app doesn't give any error, but it seems I have two instance of ServiceY.
Looking at webpack sources in chrome, i have ServiceY twice :
- webpack://
- ./node_modules/Y/src/y.service.js
- pathToX/node_modules/Y/src/y.service.js
positionning breakpoint in both ServiceY's constructors show it is stopping in both classes.
In theory ServiceY should be instanced once in my whole application since ServiceY is provided at the root of the app
I tried to add the option umdModuleIds with various values but it doesn't look to make a difference.
In conclusion, I have two unique instance of ServiceY (one being imported by app, the other imported (and redefined) by X).
Questions are :
- where is taht comming from.
- how can I be sure Y is instanciated only once in my app.
- what should I configure in umdModuleIds (how do I find moduleId)
Thanks.
Version Information
ng-packagr: 2.4.2
@angular/*: 5.2.9
typescript: ~2.4.2
rxjs: 5.5.8
node: 6.10.3
npm: 3.10.10