Recently, I made the switch from using the AngularJS 'restangular' library to the Angular 'ngx-restangular' library during an upgrade from AngularJS to Angular.
However, after the transition, I encountered an unexpected error along with a confusing stack trace:
sign-in-redirect Error: (SystemJS) Module not already loaded loading "@angular/core" as http://localhost/node_modules/@angular/core/bundles/core.umd.js.
Error: Module not already loaded loading "@angular/core" as http://localhost/node_modules/@angular/core/bundles/core.umd.js.
at Object.eval (http://localhost/node_modules/ngx-restangular/dist/umd/ngx-restangular.js:125:19)
... (error continues)
The issue seems connected to the ngx-restangular loading process. Here is a snippet of my main.ts file:
main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import '../app.js';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
In this setup, I first import the root file (app.js) for the legacy AngularJS app, followed by importing the main Angular AppModule and bootstrapping it.
AppModule.ts:
... other content...Regarding the error, I suspect that the problem lies in how I imported restangular into MyService.ts. Once I commented out the relevant line and references, the error disappeared:
import { RestangularModule, Restangular } from 'ngx-restangular';
So, what could be causing this issue and how can it be resolved?
Update:
Further investigation confirmed that the error stems from the restangular import in MyService.ts. By removing this line and related imports, the error vanished:
import { RestangularModule, Restangular } from 'ngx-restangular';
What would be the correct way to incorporate this import in my service?