Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng command throws error; @angular-devkit/core seems to be missing

Tags:

angular

I'm a little new to Angular, so apologies if this question has been asked many times. Certainly, I have found MANY github issues with similar symptoms, but no clear solution (or it's a problem that keeps coming back).

PROBLEM:

I installed whatever the latest version of Angular comes from npm:

npm install -g @angular/cli

When I run ng (with any options, even if just ng --version), I get the following error:

module.js:540     throw err;     ^  Error: Cannot find module '@angular-devkit/core'     at Function.Module._resolveFilename (module.js:538:15)     ...     ... 

APPARENT SOLUTION:

Installing @angular-devkit/core seems to fix the problem:

npm install -g @angular-devkit/core

... well, almost...

I then have to make sure I ALSO install the same devkit component for each application:

npm install --save @angular-devkit/core

QUESTIONS:

Is there a problem with Angular's packaging?

Do they deliberately leave out the devkit/core component, or just an accident with some versions?

OR, Could it be that I am doing something wrong?


SOFTWARE VERSIONS:

  • Angular CLI: 1.6.4
  • Node: 8.9.4
  • OS: linux x64
  • Angular: 5.2.1
like image 596
jehad Avatar asked Jan 18 '18 22:01

jehad


People also ask

Can not find Angular DevKit build Angular?

To solve the error "Could not find module '@angular-devkit/build-angular'", make sure to install the package by opening your terminal in your project's root directory and running the following command: npm i -D @angular-devkit/build-angular and restart your IDE and development server.

What is Angular DevKit?

Angular CLI, Angular Schematics, and Angular DevKit DevKit was built to provide libraries that can be used to manage, develop, deploy, and analyze your code. DevKit has a schematics-cli command line tool that you can use to create your own Schematics.

How do I uninstall Angular DevKit schematics?

Please remove both the "node_modules" directory and the package lock file; and then reinstall. If this does not correct the problem, please temporarily install the "@angular-devkit/schematics" package within the workspace. It can be removed once the update is complete.

Can not find module in Angular?

To solve the error "Cannot find module '@angular/core'", make sure you have installed all dependencies by running the npm install command, set the baseUrl option to src in your tsconfig. json file and restart your IDE and development server.


1 Answers

Actually, all you need is to add missing @angular-devkit/core. For some reason it's missing in the new ng new process.

npm i --save-dev @angular-devkit/core 

Of course since this is broken in 1.6.0 version you should upgrade your global @angular/cli and also your local in the project. This would make more permanent fix. The latest version also fixes missing devkit core dependency:

npm i -g @angular/cli@latest npm i --save-dev @angular/cli@latest 
like image 144
Miroslav Jonas Avatar answered Sep 19 '22 23:09

Miroslav Jonas