3

I am using example in link to learn angular. but when I run npm start it shows error. I searched for solution it ask to update npm or angular version but I am already using latest as below

npm -v = 6.4.1

node -v = 10.9.0

angular CLI = 6.1.5

I am using windows 7

 > apm@0.0.0 start F:\Angular\Angular-GettingStarted-master\APM-Start
 > ng serve -o

 npm ERR! file bash
 npm ERR! path bash
 npm ERR! code ELIFECYCLE
 npm ERR! errno ENOENT
 npm ERR! syscall spawn bash
 npm ERR! apm@0.0.0 start: `ng serve -o`
 npm ERR! spawn bash ENOENT
 npm ERR!
 npm ERR! Failed at the apm@0.0.0 start script.
 npm ERR! This is probably not a problem with npm. There is likely 
 additional logging output above.

 npm ERR! A complete log of this run can be found in:
 npm ERR!     C:\Users\AppData\Roaming\npm-cache\_logs\2018-09- 
 05T16_12_41_076Z-debug.log
hrishi
  • 1,610
  • 6
  • 26
  • 43
  • Which link are you using again? It didn't load as a part of this question. Please consider adding it again. – SiddAjmera Sep 05 '18 at 17:28
  • I updated link in question. – hrishi Sep 05 '18 at 18:24
  • 2
    Did you run `npm install` before trying `ng serve`? – peinearydevelopment Sep 05 '18 at 18:26
  • 1
    Also, if angular-cli isn't installed globally, after `npm install` you will have to run the command as follows `node_modules/.bin/ng serve` or `npm run start`. – peinearydevelopment Sep 05 '18 at 18:27
  • You should be running `ng serve` instead of `npm start` I guess. – SiddAjmera Sep 05 '18 at 18:28
  • Yes ng serve solved the issue but now it shows error as ERROR in ./ansi-html Module parse failed: Unexpected character '#' (1:0) You may need an appropriate loader to handle this file type. – hrishi Sep 05 '18 at 19:42
  • https://github.com/webpack-contrib/sass-loader/issues/518 – Sajeetharan Sep 08 '18 at 05:58
  • It do not help. I really do not understand why this error shows. and how to fix it. I now created new project using ng new. and it gives same error ERROR in ./ansi-html Module parse failed: Unexpected character '#' (1:0) You may need an appropriate loader to handle this file type.` – hrishi Sep 08 '18 at 15:17
  • Have you thought of starting from scratch again. I just downloaded it and everything worked fine. I am using VS Code, and apart from CLI (mine is lower version), every thing is same. – r2018 Sep 10 '18 at 15:53

2 Answers2

8

Your node version seems to be too higher. Please downgrade node version to 8.9.0. (Confirm that your npm version also gets downgraded based on node).

Delete your node_modules folder.

Then run commands in sequence:

npm cache clean --force

npm install

npm rebuild node-sass

Then try: ng serve

Gourav Pokharkar
  • 1,568
  • 1
  • 11
  • 33
  • I installed version 8.9.0 and npm -v gives error 'Error: Cannot find module 'C:\Windows\System32\node_modules\npm\bin\npm-cli.js'. I set environment variable to 'C:\Program Files\nodejs' still same error – hrishi Sep 09 '18 at 19:17
  • there is no node_modules in System32 – hrishi Sep 09 '18 at 19:20
  • Did you install node as administrator? If not, try installing as administrator. – Gourav Pokharkar Sep 09 '18 at 20:03
  • Yes I installed it as administrator – hrishi Sep 10 '18 at 04:15
  • Seems that your node.js did not install correctly. Please uninstall all node.js versions from 'Control Panel'. Check if it's uninstalled properly using `node -v`. Then try again installing node 8.9.0. Still problem persists, refer this post: https://stackoverflow.com/q/24721903/6848923 and try the solutions. – Gourav Pokharkar Sep 10 '18 at 05:07
  • Finally it is working now after downgrade node and putting paths in environment variables – hrishi Sep 11 '18 at 17:13
  • Good job. Happy for you. – Gourav Pokharkar Sep 12 '18 at 10:24
1

wow it was crazy. I solved this by

  1. uninstalling node and restarting my Machine.
  2. downloading a new version of node from here which was the LTS version
  3. installed this new version of node i downloaded.
  4. ran npm cache clean --force
  5. ran npm install in the project directory. and voila its ALIVE!!! it worked.
chie7tain
  • 41
  • 2