node.jsangularmacosionic-framework

Ionic serve Cannot GET / Cannot find module '@ionic-native/splash-screen/ngx'


I'm trying to run Ionic and used the Ionic framework Ionic docs tutorial to install, but when I run Ionic serve, my browser opens to an error, 'Cannot GET /'

I installed with npm install -g @ionic/cli and created the base template tabs, ionic start myApp tabs

This is the error from ionic serve

> ng run app:serve --host=localhost --port=8100
[ng] Browserslist: caniuse-lite is outdated. Please run next command `npm update`
[ng] ℹ 「wds」: Project is running at http://localhost:8100/webpack-dev-server/
[ng] ℹ 「wds」: webpack output is served from /
[ng] ℹ 「wds」: 404s will fallback to //index.html
[ng] chunk {main} main.js, main.js.map (main) 2.03 kB [initial] [rendered]
[ng] chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 149 kB [initial] [rendered]
[ng] chunk {runtime} runtime.js, runtime.js.map (runtime) 6.09 kB [entry] [rendered]
[ng] chunk {styles} styles.js, styles.js.map (styles) 109 kB [initial] [rendered]
[ng] chunk {vendor} vendor.js, vendor.js.map (vendor) 339 kB [initial] [rendered]
[ng] Date: 2020-02-11T03:56:39.914Z - Hash: 9860ec75ab31a30a881b - Time: 5271ms
[ng] 
[ng] ERROR in src/app/app.component.ts:4:30 - error TS2307: Cannot find module '@ionic-native/splash-screen/ngx'.
[ng] 4 import { SplashScreen } from '@ionic-native/splash-screen/ngx';
[ng]                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ng] src/app/app.module.ts:6:30 - error TS2307: Cannot find module '@ionic-native/splash-screen/ngx'.
[ng] 6 import { SplashScreen } from '@ionic-native/splash-screen/ngx';
[ng]                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ng] 

[INFO] Development server running!

       Local: http://localhost:8100

       Use Ctrl+C to quit this process

[INFO] Browser window opened to http://localhost:8100!

[ng] ℹ 「wdm」: Failed to compile.

This my ionic info

Ionic:

   Ionic CLI                     : 6.0.2 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 4.11.10
   @angular-devkit/build-angular : 0.801.3
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.1.2

Capacitor:

   Capacitor CLI   : 1.5.0
   @capacitor/core : 1.5.0

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   NodeJS : v13.2.0 (/usr/local/bin/node)
   npm    : 6.13.1
   OS     : macOS Catalina

Strangely, when I run ionic serve -l for the lab, it gives me 2 black screens instead of the base template tabs.

I've tried deleting the node modules folder and re-running npm install, but I'm still getting the same error.

My package.json does contain the @ionic-native

    "@ionic-native/core": "^5.0.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",

How do I get @ionic-native/splash-screen/ngx?


Solution

  • I just updated to Ionic CLI 6.1.0 and Framework Angular 5.0.0 and this error doesn't occur anymore.

    First check your dependencies, go to the ionic folder and type in % npm list --depth=0 Fix all dependencies, if that still doesn't work then proceed with instructions below, these may or may not work because it worked for tabs, blank and sidemenu, but when I installed the conference app, it's now working perfectly through just ionic serve.

    [ng] 4 import { SplashScreen } from '@ionic-native/splash-screen/ngx';

    So on the ionic framework version @ionic/angular 4.11.6 and ionic cli 6.0+, @ionic-native/splash-screen/ngx does not exist, the solution is to remove /ngx.

    Aka change import { SplashScreen } from '@ionic-native/splash-screen/ngx'; to import { SplashScreen } from '@ionic-native/splash-screen';

    Everywhere you find it, and it seems to add that by default in the blank, tabs and sidemenu, conference app templates.

    By default it exists in src/apps/app.components.ts and src/apps/app.modules.ts