Error: NativeScriptModule has already been loaded


I’ve upgraded my application with nativescript 4.0.0 and a few other modules in my package.json. Now I get this error when I try to access a page which has its own module : Error: Uncaught (in promise): Error: NativeScriptModule has already been loaded. Import NativeScriptModule in the AppModule only.

I’ve deleted all modules in the problematic module but still get this error, any ideas ?


As you might already know NativeScriptModule should be included only once in app. NativeScriptCommonModule is not supposed to be imported in your app module.

May be you can share the list of imports in your app module which might give us some idea on this issue.


Yes I know about this rules, here is my app.module imports :
imports: [ NativeScriptModule, NativeScriptFormsModule, NativeScriptHttpModule, NativeScriptRouterModule, appRouting, TNSCheckBoxModule, SharedModule.forRoot() ],


May I know what you have inside shared module?


Sure, in shared.module I have : imports: [ NativeScriptCommonModule, NativeScriptUISideDrawerModule ],

and in search.module : imports:[ searchRouting, ]


NativeScriptCommonModule suppose not to be imported in AppModule where you already have NativeScriptModule. Usually SharedModule won’t be imported in AppModule until it’s just a place holder to declare other modules.


I removed sharedModule.forRoot() from AppModule but I still have the error. It is weird message as I am not loading NativeScriptModule a second time and did not change code after the upgrade …


Hey I had the same for my Nativescript Angular app. All my routes were lazy loaded and since the upgrade, only my startup lazy module loads. After that all lazy loaded modules routed to cause this error.

But as mentioned by removing the NativeScriptModule for me the error is removed. So in each of my lazy loading modules I removed the import { NativeScriptModule } from “nativescript-angular/nativescript.module”;