0

I have installed angular cli 1.5 from the command below:

C:\ANGULAR-WORKBENCH>npm install --global @angular/cli@1.5.0

after completion of installation the following lines were displayed on terminal

+ @angular/cli@1.5.0
added 115 packages and updated 1 package in 105.694s

Then I have tested if it was successfully installed by

C:\ANGULAR-WORKBENCH>ng -version

or

C:\ANGULAR-WORKBENCH>ng

In Both cases it displayed the error

module.js:538 throw err; ^
Error: Cannot find module '@angular-devkit/core' at Function.Module._resolveFilename (module.js:536:15) at Function.Module._load (module.js:466:25) at Module.require (module.js:579:17) at require (internal/module.js:11:18) at Object. (C:\Users\User1\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\src\tree\virtual.js:10:16) at Module._compile (module.js:635:30) at Object.Module._extensions..js (module.js:646:10) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12) at Function.Module._load (module.js:489:3)

Why this throws the error? How do i fix this issue?

Melchia
  • 22,578
  • 22
  • 103
  • 117
ng mathitis
  • 31
  • 1
  • 2
  • 1
    This isn't something SO can help with, it's a [known issue](https://github.com/angular/angular-cli/issues/9307) in a third party library. – jonrsharpe Mar 10 '18 at 13:46
  • Is version 1.5.0 a must for you? Otherwise I would take the @latest. I had the same problem as you with a newer version of the cli and by installing the latest version globally and locally the problem was solved. – zgue Mar 10 '18 at 14:04

4 Answers4

1

Perhaps the problem is that you are installing and old angular/cli version, try running this commands in your terminal:

npm uninstall -g angular-cli
npm cache clean or npm cache verify #(if npm > 5)
npm install -g @angular/cli@latest

If you need more datailed explanation please check this link: https://stackoverflow.com/a/43931987/8992452, it worked for me.

NUKE
  • 71
  • 1
  • 6
0

All you need to do is run npm i -D @angular-devkit/core in the working directory to fix it.

Vikas
  • 11,859
  • 7
  • 45
  • 69
  • Actually, no. The OP hasn't even build a new project yet. The command above would fail if you just run that without being in a project folder. – R. Richards Mar 10 '18 at 14:12
  • Since the issue was cropped up by running ng serve, I assumed that he is currently in the working directory – Vikas Mar 10 '18 at 14:30
  • The OP doesn't mention `ng serve`. `ng` and `ng -version`, but not serve. – R. Richards Mar 10 '18 at 14:32
  • I have edited my answer, I hope it is correct now @ R. Richards – Vikas Mar 10 '18 at 14:42
  • @Vikas i did run npm i -D @angular-devkit/core but still gives the same issue – ng mathitis Mar 10 '18 at 23:09
  • i'm ok to install cli version 1.6 but would i be able to do angular 5 development with it and if i had installed version 1.5? – ng mathitis Mar 10 '18 at 23:10
  • yes, you can cli version >=1.5 will generate v5 projects by default, but it's better to keep the global and local version of cli in sync see this- https://stackoverflow.com/a/44526528/5695162 – Vikas Mar 11 '18 at 06:21
0

You're using an old angular cli version. Try updating it:

$ npm install -g @angular/cli@^1.6.5 
Melchia
  • 22,578
  • 22
  • 103
  • 117
0

In some systems, ng commands won't work (Usually in company laptops). Anyway, npm commands will run. So the workaround would be in the package.json file to add the relevent scripts to run your project.

For instance, if you want to start your project, the Angular way would be: ng server.

But you can also run npm start.

To build your project, add the ng build <some-options> into the package.json scripts object. For example, scripts: {"build": "ng build --aot=false"}

Then run npm run build.

Hope this helps!