Error on executing 'ionic serve' on a fresh installation of npm, angular cli and ionic - Cannot find module @angular\cli\bin\ng

Installed the latest stable version of node/npm and angular cli (both globally). My angular projects are working fine (i.e. ng serve works fine).
$ node -v
v12.14.0
$ npm -v
6.13.4

Then i installed ionic - npm install – g ionic
Then created my ionic project and ran ionic serve. But it throws an error:

ng run app:serve --host=0.0.0.0 --port=8100
[ng] The system cannot find the path specified.
[ng] internal/modules/cjs/loader.js:800
[ng] throw err;
[ng] ^
[ng] Error: Cannot find module ‘D:\0. Mayank 2020 - Laptop@angular\cli\bin\ng’
[ng] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
[ng] at Function.Module._load (internal/modules/cjs/loader.js:690:27)
[ng] at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
[ng] at internal/main/run_main_module.js:17:11 {
[ng] code: ‘MODULE_NOT_FOUND’,
[ng] requireStack:
[ng] }

[ERROR] ng has unexpectedly closed (exit code 1).

    The Ionic CLI will exit. Please check any output above for error details.

Thereafter I installed an earlier version of ionic - i.e. 4,12,0. But the error persists.

I am using Git Bash terminal on windows. Tried the same in command prompt too but the same error is thrown.

My package.json file:
{

“name”: “hello-world2”,

“version”: “0.0.1”,

“author”: “Ionic Framework”,

“homepage”: “https://ionicframework.com/”,

“scripts”: {

"ng": "ng",

"start": "ng serve",

"build": "ng build",

"test": "ng test",

"lint": "ng lint",

"e2e": "ng e2e"

},

“private”: true,

“dependencies”: {

"@angular/common": "~8.1.2",

"@angular/core": "~8.1.2",

"@angular/forms": "~8.1.2",

"@angular/platform-browser": "~8.1.2",

"@angular/platform-browser-dynamic": "~8.1.2",

"@angular/router": "~8.1.2",

"@ionic-native/core": "^5.0.0",

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

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

"@ionic/angular": "^4.7.1",

"core-js": "^2.5.4",

"rxjs": "~6.5.1",

"tslib": "^1.9.0",

"zone.js": "~0.9.1"

},

“devDependencies”: {

"@angular-devkit/architect": "~0.801.2",

"@angular-devkit/build-angular": "~0.801.2",

"@angular-devkit/core": "~8.1.2",

"@angular-devkit/schematics": "~8.1.2",

"@angular/cli": "~8.1.2",

"@angular/compiler": "~8.1.2",

"@angular/compiler-cli": "~8.1.2",

"@angular/language-service": "~8.1.2",

"@ionic/angular-toolkit": "^2.1.1",

"@types/jasmine": "~3.3.8",

"@types/jasminewd2": "~2.0.3",

"@types/node": "~8.9.4",

"codelyzer": "^5.0.0",

"jasmine-core": "~3.4.0",

"jasmine-spec-reporter": "~4.2.1",

"karma": "~4.1.0",

"karma-chrome-launcher": "~2.2.0",

"karma-coverage-istanbul-reporter": "~2.0.1",

"karma-jasmine": "~2.0.1",

"karma-jasmine-html-reporter": "^1.4.0",

"protractor": "~5.4.0",

"ts-node": "~7.0.0",

"tslint": "~5.15.0",

"typescript": "~3.4.3"

},

“description”: “An Ionic project”

}

1 Like

That path seems to have lots of weird characters in it. Can you try using folder names that are just a-z?

I have installed npm, angular cli and ionic globally. So the folder where my projects are should not matter. Also, my angular apps are working fine, which means my npm and angular cli is ok. The problem is related to ionic.
My ng module is in C:\Users\MAYANK\AppData\Roaming\npm\node_modules@angular\cli\bin (installed globally)
But ionic serve is complaining that it cannot find ng module in D:\0. Mayank 2020 - Laptop@angular\cli\bin\ng , where my projects are !!!

Solution: The reply of ionic moderator was right indeed… I don’t know how and why, but it was. The error was being thrown when I created my project in the folder:

D:\0. Mayank 2020 - Laptop\Technical - R&D\Ionic Apps

But it worked well when I created my project in the folder:

D:\Ionic Apps

But now there are a couple of new problems I am facing:
Now when I create a new ionic project using ionic start, the project is created but ionic start command does not stop executing on its own and I have to press cntrl+c to stop it.
Also, when I run ionic start I am not able to choose the framework and template of my choice, as I cannot move the arrows using the arrow keys of my laptop…so I always end up choosing the first ones on the list, vis Angular framework and tab template.
(though I can work on my ionic project now but these issues are a little frustrating)

Just had the same exact problem. Renaming folders fixed it.