Cannot emulate app

I used to be able to emulate my app, but recently I have been getting some weird errors, not sure what caused it. Here is my error from the command prompt:

C:\myApp>ionic cordova run android
module.js:471
throw err;
^

Error: Cannot find module 'C:\Users*myname*\AppData\Roaming\npm\node_modules\ionic\bin\ionic’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3

C:\myApp>

What is your ionic info output?
What does ionic cordova run android --verbose -- --debug output?

Any command beginning with “ionic” seems to output that exact same error.

Also outside of your current Ionic project?
If not, can you create a new project with ionic start from a folder that is not a Ionic project right now?

Yes, the error occurs outside of my current project directory and ionic start also triggers the same error.

First run npm list -g --depth=0 and post the output.
Then nuke your ionic install with npm uninstall -g ionic and reinstall with npm install -g ionic and try again.
Run the list ... command from above again and post the output.

I would suggest taking this opportunity to install nvm-windows.

Yeah, if this doesn’t work go one level deeper and also fix your Node:
Uninstall your node, install nvm (or nvm-windows if you are on Windows), install a new node (which includes npm) with this, then install ionic and cordova again and try your command again. The problem should be gone.

First time running the given command gives the output:

C:\myApp>npm list -g --depth=0
C:\Users\David Biggs\AppData\Roaming\npm
±- myapp@0.0.3
`-- npm@5.4.1

npm ERR! peer dep missing: @angular/core@4.1.3, required by @angular/common@4.1.3
npm ERR! peer dep missing: @angular/core@4.1.3, required by @angular/compiler@4.1.3
npm ERR! peer dep missing: @angular/core@4.1.3, required by @angular/compiler-cli@4.1.3
npm ERR! peer dep missing: @angular/core@4.1.3, required by @angular/forms@4.1.3
npm ERR! peer dep missing: @angular/core@4.1.3, required by @angular/http@4.1.3
npm ERR! peer dep missing: @angular/core@4.1.3, required by @angular/platform-browser@4.1.3
npm ERR! peer dep missing: @angular/core@4.1.3, required by @angular/platform-browser-dynamic@4.1.3
npm ERR! peer dep missing: @angular/core@2.4.8, required by @ionic-native/ad-mob@3.1.1
npm ERR! peer dep missing: @angular/core@4.1.3, required by ionic-angular@3.5.0
npm ERR! peer dep missing: @ionic-native/core@3.1.1, required by @ionic-native/ad-mob@3.1.1
npm ERR! peer dep missing: rxjs@5.0.1, required by @ionic-native/ad-mob@3.1.1
npm ERR! peer dep missing: rxjs@5.4.0, required by ionic-angular@3.5.0
npm ERR! peer dep missing: zone.js@^0.7.2, required by @angular/core@2.4.10
npm ERR! peer dep missing: typescript@^2.0.2, required by @angular/compiler-cli@4.1.3
npm ERR! peer dep missing: typescript@^2.1.5, required by @angular/tsc-wrapped@4.1.3
npm ERR! peer dep missing: typescript@^2.1.0, required by tsickle@0.21.6

And running it a second time gives me:

C:\myApp>npm install -g ionic
C:\Users\David Biggs\AppData\Roaming\npm\ionic -> C:\Users\David Biggs\AppData\Roaming\npm\node_modules\ionic\bin\ionic
npm ERR! path C:\Users\David Biggs\AppData\Roaming\npm\node_modules\ionic\node_modules\nan\package.json
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Users\David Biggs\AppData\Roaming\npm\node_modules\ionic\node_modules\nan\package.json’
npm ERR! at Error (native)
npm ERR! { Error: EPERM: operation not permitted, unlink 'C:\Users\David Biggs\AppData\Roaming\npm\node_modules\ionic\node_modules\nan\package.json’
npm ERR! at Error (native)
npm ERR! stack: ‘Error: EPERM: operation not permitted, unlink ‘C:\Users\David Biggs\AppData\Roaming\npm\node_modules\ionic\node_modules\nan\package.json’\n at Error (native)’,
npm ERR! errno: -4048,
npm ERR! code: ‘EPERM’,
npm ERR! syscall: ‘unlink’,
npm ERR! path: ‘C:\Users\David Biggs\AppData\Roaming\npm\node_modules\ionic\node_modules\nan\package.json’ }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\David Biggs\AppData\Roaming\npm-cache_logs\2017-09-14T19_23_52_775Z-debug.log

EDIT: I posted the wrong command for the second one, but as you can see ionic is not properly installing anyway… I am running as administrator and I also am on windows.

Yeo, your node and npm are borked. Follow what I wrote above and install nvm-windows.

Okay, so I uninstalled npm and then installed nvm, however now when I install the latest node version, the accompanying npm install does not complete. It says the filename or extension is too long.

C:\myApp>nvm install latest
Downloading node.js version 8.5.0 (64-bit)…
Complete
Downloading npm version 5.3.0… Complete
Installing npm v5.3.0…2017/09/14 15:20:47 mkdir C:\Users\David Biggs\AppData\Roaming\nvm\temp\nvm-npm\npm-5.3.0\node_modules\libnpx\node_modules\yargs\node_modules\read-pkg-up\node_modules\read-pkg\node_modules\load-json-file\node_modules\parse-json\node_modules\error-ex\node_modules\is-arrayish: The filename or extension is too long.

You are on Windows. You should install nvm-windows, after uninstalling not just your npm but also Node.js.

Oh I’m sorry, that’s nvm-windows. Do I need to modify the PATH environment variable to keep the filename or extension from being too long?

I uninstalled node.js as well

That path looks wrong… where did you install nvm and set its data directory?

C:\Users\David Biggs\AppData\Roaming\nvm

I believe I’ve seen people on Windows posting problems with project names that have spaces in them. Not sure if that applies to user names as well, but might be worth eliminating.

Choose C:\nvm. Everything in the user directory is “special”. You don’t want to have node and npm in a special directory. That is actually the point behind installing nvm-windows - it enables this while node.js itself does not.

Okay, the installation of node and npm worked correctly, but now here’s the error I get:

C:\myApp>ionic cordova run android
TypeError: _angular_core.InjectionToken is not a constructor
at C:\myApp\node_modules@angular\compiler\bundles\compiler.umd.js:11979:27
at C:\myApp\node_modules@angular\compiler\bundles\compiler.umd.js:7:65
at Object. (C:\myApp\node_modules@angular\compiler\bundles\compiler.umd.js:10:2)
at Module._compile (module.js:624:30)
at Object.Module._extensions…js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)

EDIT: here is my package.json (the board won’t let me post any faster)

{
“name”: “myapp”,
“version”: “0.0.3”,
“author”: “Ionic Framework”,
“homepage”: “http://ionicframework.com/”,
“private”: true,
“scripts”: {
“clean”: “ionic-app-scripts clean”,
“build”: “ionic-app-scripts build”,
“lint”: “ionic-app-scripts lint”,
“ionic:build”: “ionic-app-scripts build”,
“ionic:serve”: “ionic-app-scripts serve”
},
“dependencies”: {
"@angular/common": “4.1.3”,
"@angular/compiler": “4.1.3”,
"@angular/compiler-cli": “4.1.3”,
"@angular/core": “^2.4.8”,
"@angular/forms": “4.1.3”,
"@angular/http": “4.1.3”,
"@angular/platform-browser": “4.1.3”,
"@angular/platform-browser-dynamic": “4.1.3”,
"@ionic-native/ad-mob": “^3.1.1”,
"@ionic-native/admob-free": “^4.1.0”,
"@ionic-native/core": “^3.1.1”,
"@ionic-native/in-app-browser": “^4.1.0”,
"@ionic-native/splash-screen": “^3.12.1”,
"@ionic-native/status-bar": “3.12.1”,
"@ionic/storage": “2.0.1”,
“ajv”: “^5.2.2”,
“angular”: “^1.6.6”,
“cordova”: “^7.0.1”,
“cordova-admob-sdk”: “^0.7.0”,
“cordova-android”: “^6.2.3”,
“cordova-browser”: “^4.1.0”,
“cordova-ios”: “^4.4.0”,
“cordova-plugin-admob-free”: “^0.9.0”,
“cordova-plugin-admobpro”: “^2.29.21”,
“cordova-plugin-console”: “^1.0.5”,
“cordova-plugin-device”: “^1.1.4”,
“cordova-plugin-extension”: “^1.5.1”,
“cordova-plugin-inappbrowser”: “^1.7.1”,
“cordova-plugin-splashscreen”: “^4.0.3”,
“cordova-plugin-statusbar”: “^2.2.2”,
“cordova-plugin-whitelist”: “^1.3.1”,
“cordova-promise-polyfill”: “0.0.2”,
“ionic-angular”: “3.5.0”,
“ionic-plugin-keyboard”: “^2.2.1”,
“ionicons”: “3.0.0”,
“rxjs”: “^5.4.0”,
“sw-toolbox”: “3.6.0”,
“zone.js”: “0.8.12”
},
“devDependencies”: {
"@ionic/app-scripts": “2.0.0”,
“ionic”: “^3.10.3”,
“typescript”: “2.3.4”
},
“description”: “An Ionic project”,
“cordova”: {
“plugins”: {
“cordova-plugin-admob-free”: {},
“cordova-plugin-console”: {},
“cordova-plugin-device”: {},
“cordova-plugin-splashscreen”: {},
“cordova-plugin-statusbar”: {},
“cordova-plugin-whitelist”: {},
“ionic-plugin-keyboard”: {},
“cordova-plugin-admobpro”: {},
“cordova-plugin-inappbrowser”: {}
},
“platforms”: [
“android”,
“browser”,
“ios”
]
}
}

That suggests to me that your @angular/compiler is too old. Can you show package.json?

Here:

{
“name”: “myapp”,
“version”: “0.0.3”,
“author”: “Ionic Framework”,
“homepage”: “http://ionicframework.com/”,
“private”: true,
“scripts”: {
“clean”: “ionic-app-scripts clean”,
“build”: “ionic-app-scripts build”,
“lint”: “ionic-app-scripts lint”,
“ionic:build”: “ionic-app-scripts build”,
“ionic:serve”: “ionic-app-scripts serve”
},
“dependencies”: {
"@angular/common": “4.1.3”,
"@angular/compiler": “4.1.3”,
"@angular/compiler-cli": “4.1.3”,
"@angular/core": “^2.4.8”,
"@angular/forms": “4.1.3”,
"@angular/http": “4.1.3”,
"@angular/platform-browser": “4.1.3”,
"@angular/platform-browser-dynamic": “4.1.3”,
"@ionic-native/ad-mob": “^3.1.1”,
"@ionic-native/admob-free": “^4.1.0”,
"@ionic-native/core": “^3.1.1”,
"@ionic-native/in-app-browser": “^4.1.0”,
"@ionic-native/splash-screen": “^3.12.1”,
"@ionic-native/status-bar": “3.12.1”,
"@ionic/storage": “2.0.1”,
“ajv”: “^5.2.2”,
“angular”: “^1.6.6”,
“cordova”: “^7.0.1”,
“cordova-admob-sdk”: “^0.7.0”,
“cordova-android”: “^6.2.3”,
“cordova-browser”: “^4.1.0”,
“cordova-ios”: “^4.4.0”,
“cordova-plugin-admob-free”: “^0.9.0”,
“cordova-plugin-admobpro”: “^2.29.21”,
“cordova-plugin-console”: “^1.0.5”,
“cordova-plugin-device”: “^1.1.4”,
“cordova-plugin-extension”: “^1.5.1”,
“cordova-plugin-inappbrowser”: “^1.7.1”,
“cordova-plugin-splashscreen”: “^4.0.3”,
“cordova-plugin-statusbar”: “^2.2.2”,
“cordova-plugin-whitelist”: “^1.3.1”,
“cordova-promise-polyfill”: “0.0.2”,
“ionic-angular”: “3.5.0”,
“ionic-plugin-keyboard”: “^2.2.1”,
“ionicons”: “3.0.0”,
“rxjs”: “^5.4.0”,
“sw-toolbox”: “3.6.0”,
“zone.js”: “0.8.12”
},
“devDependencies”: {
"@ionic/app-scripts": “2.0.0”,
“ionic”: “^3.10.3”,
“typescript”: “2.3.4”
},
“description”: “An Ionic project”,
“cordova”: {
“plugins”: {
“cordova-plugin-admob-free”: {},
“cordova-plugin-console”: {},
“cordova-plugin-device”: {},
“cordova-plugin-splashscreen”: {},
“cordova-plugin-statusbar”: {},
“cordova-plugin-whitelist”: {},
“ionic-plugin-keyboard”: {},
“cordova-plugin-admobpro”: {},
“cordova-plugin-inappbrowser”: {}
},
“platforms”: [
“android”,
“browser”,
“ios”
]
}
}

also, annoyingly, the forum won’t let me post very fast, so I’m having to wait like 10 mins every time I want to post. :frowning: