Unable to import CoreModule inside lazy loaded modules.

cancel
Showing results for 
Search instead for 
Did you mean: 
yadavami
Member II

Unable to import CoreModule inside lazy loaded modules.

I have a common module where all the dependencies related to Alfresco are imported(containing CoreModule), now when I try to inject this common module inside my lazyloaded module it does not work.

Console Error :

ERROR Error: Uncaught (in promise): Error: BrowserModule has already been loaded. If you need access to common Rdirectives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.
Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.
at new BrowserModule (platform-browser.js:4579)
at _createClass (core.js:10915)
at _createProviderInstance$1 (core.js:10889)
at initNgModule (core.js:10842)
at new NgModuleRef_ (core.js:12096)
at createNgModuleRef (core.js:12086)
at Object.debugCreateNgModuleRef [as createNgModuleRef] (core.js:14430)
at NgModuleFactory_.create (core.js:15575)
at MapSubscriber.eval [as project] (router.js:4507)
at MapSubscriber._next (map.js:79)
at new BrowserModule (platform-browser.js:4579)
at _createClass (core.js:10915)
at _createProviderInstance$1 (core.js:10889)
at initNgModule (core.js:10842)
at new NgModuleRef_ (core.js:12096)
at createNgModuleRef (core.js:12086)
at Object.debugCreateNgModuleRef [as createNgModuleRef] (core.js:14430)
at NgModuleFactory_.create (core.js:15575)
at MapSubscriber.eval [as project] (router.js:4507)
at MapSubscriber._next (map.js:79)
at resolvePromise (zone.js:783)
at resolvePromise (zone.js:754)
at eval (zone.js:831)
at ZoneDelegate.invokeTask (zone.js:424)
at Object.onInvokeTask (core.js:4744)
at ZoneDelegate.invokeTask (zone.js:423)
at Zone.runTask (zone.js:191)
at drainMicroTaskQueue (zone.js:595)

6 Replies
Moderator
Moderator

Re: Unable to import CoreModule inside lazy loaded modules.

This is a known issue and already in our backlog. To unblock development you can meanwhile use standard routes and switch to lazy loaded ones as soon as issue is resolved.

yadavami
Member II

Re: Unable to import CoreModule inside lazy loaded modules.

Our project structure and requirement does not allow to use standard routes.
We are left one option that is updating CoreModule and maintain it locally could you suggest some pointer for the same.

Thanks

Moderator
Moderator

Re: Unable to import CoreModule inside lazy loaded modules.

If you know what needs to be done to make CoreModule fully compatible with the lazy loading (including Translate service I believe), then you could create a contribution pull request instead of maintaining a local copy.

Moderator
Moderator

Re: Unable to import CoreModule inside lazy loaded modules.

With 2.1 release it should be possible using lazy-loaded modules, including i18n resources that a local to the lazy module.

nelsonneves
Member II

Re: Unable to import CoreModule inside lazy loaded modules.

Hello.

I have a shared-module where I'm importing all the alfresco modules (like CoreModule.forChild()) when I try to import that shared module in a lazy loading module, I have issues with the translation providers, it seems to load a TranslateFakeLoader instead of the TranslateLoaderService. 

It runs twice the first time it catchs the TranslateLoaderService but then it catches the TranslateFakeLoader and blows when it tries to call the "setDefaultLang" (this.customLoader.setDefaultLang(this.defaultLang)#adf-core.js).

Note: I'm exporting the Alfresco modules on the sharedModule.

Can anyone help me please?

Community Manager
Community Manager

Re: Unable to import CoreModule inside lazy loaded modules.

Hi @nelsonneves,

It's probably better to start this as a new thread (eventhough it's related) because people often overlook threads they've already read but not subscribed to.

HTH, 

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!