Skip to content

bug: Ionic Angular was already initialized. Make sure IonicModule.forRoot() is just called once. #19926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
josh-m-sharpe opened this issue Nov 16, 2019 · 7 comments · Fixed by #23292
Labels
package: angular @ionic/angular package type: bug a confirmed bug report

Comments

@josh-m-sharpe
Copy link

Bug Report

Ionic version:
[x] 4.x

Current behavior:
Create a new ionic angular app. Run the tests.

Expected behavior:
No warnings would be displayed.

This becomes more pervasive as the test suite grows. I see this warning numerous times throughout my real apps. Why is it there and how do we remove it? Is the generator setting up tests incorrectly?

Steps to reproduce:
git clone https://github.com/josh-m-sharpe/bareCapacitorApp.git
yarn install
npm run test

> bareCapacitorApp@0.0.1 test /Users/jsharpe/bareCapacitorApp
> ng test

 10% building 1/1 modules 0 active16 11 2019 06:46:05.349:WARN [karma]: No captured browser, open http://localhost:9876/
16 11 2019 06:46:05.420:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
16 11 2019 06:46:05.420:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
16 11 2019 06:46:05.426:INFO [launcher]: Starting browser Chrome
16 11 2019 06:46:13.256:WARN [karma]: No captured browser, open http://localhost:9876/
16 11 2019 06:46:13.490:INFO [Chrome 78.0.3904 (Mac OS X 10.14.6)]: Connected on socket YbYWbp2Wnno-nsT5AAAA with id 37625611
Chrome 78.0.3904 (Mac OS X 10.14.6): Executed 0 of 6 SUCCESS (0 secs / 0 secs)
16 11 2019 06:46:16.551:WARN [web-server]: 404: /svg/md-book.svg
16 11 2019 06:46:16.553:WARN [web-server]: 404: /svg/md-build.svg
16 11 2019 06:46:16.555:WARN [web-server]: 404: /svg/md-grid.svg
WARN: 'Ionic Angular was already initialized. Make sure IonicModule.forRoot() is just called once.'
Chrome 78.0.3904 (Mac OS X 10.14.6): Executed 1 of 6 SUCCESS (0 secs / 0.465 secs)
WARN: 'Ionic Angular was already initialized. Make sure IonicModule.forRoot() is just called once.'
Chrome 78.0.3904 (Mac OS X 10.14.6): Executed 2 of 6 SUCCESS (0 secs / 0.698 secs)
Chrome 78.0.3904 (Mac OS X 10.14.6): Executed 4 of 6 SUCCESS (0 secs / 0.954 secs)
16 11 2019 06:46:17.093:WARN [web-server]: 404: /svg/md-flash.svg
16 11 2019 06:46:17.096:WARN [web-server]: 404: /svg/md-apps.svg
Chrome 78.0.3904 (Mac OS X 10.14.6): Executed 6 of 6 SUCCESS (1.07 secs / 0.995 secs)
TOTAL: 6 SUCCESS
TOTAL: 6 SUCCESS
@ionitron-bot ionitron-bot bot added the triage label Nov 16, 2019
@liamdebeasi liamdebeasi added package: angular @ionic/angular package type: bug a confirmed bug report labels Nov 18, 2019
@ionitron-bot ionitron-bot bot removed the triage label Nov 18, 2019
@DavidFrahm
Copy link

I'm seeing this in a new app I just created a few weeks ago. I have been doing Ionic / Stencil (no framework) for a couple years so I'm not sure if this is a new warning, something I'm doing wrong, etc.

In a current Ionic 4 / Angular 8 application with two page components, each with a test suite, when run either individually there is no WARN. However, run them both together, and WARN is output for second test.

@jonathan-chin
Copy link

I just upgraded my application to Ionic 4 / Angular 8 from Ionic 4 / Angular 6 and am getting the same.

I didn't notice this warning message before but it's popping up now when I run ionic serve. I haven't tested it yet on production builds.

@Rajatsoni9
Copy link
Contributor

These warnings are due to multiple calls to IonicModule.forRoot() in each test suite. If you replace it with just IonicModule in the imports array in the testing module, the warnings disappear.

@KevinBassaDevelopment
Copy link

@Rajatsoni9 if only IonicModule is used it will not build up the Shadow DOM correctly.
Then a lot of things, like the text content of ion-text-area, cannot be tested.

@jakobe
Copy link
Contributor

jakobe commented Nov 9, 2020

Since we currently can't prevent the warning, our workaround is to patch the console with a check for the specific warning message and mute it:

function muteIonicReInitializeWarning() {
    const originalWarn = console.warn;
    const patchedWarn = (warning: any, ...optionalParams: any[]) => {
      const suppress = `Ionic Angular was already initialized. Make sure IonicModule.forRoot() is just called once.`;
      if (warning !== suppress) originalWarn(warning, ...optionalParams);
    };
    console.warn = patchedWarn;
  }

@liamdebeasi
Copy link
Contributor

Thanks for the issue. This has been resolved via #23292, and a fix will be available in an upcoming release of Ionic Framework.

@ionitron-bot
Copy link

ionitron-bot bot commented Jun 10, 2021

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jun 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: angular @ionic/angular package type: bug a confirmed bug report
Projects
None yet
7 participants