How to resolve “Error: Cannot find module ‘@angular-devkit/core’ – after clean install”

Background

This error can occur when you have just started learning angular or are already an expert into it. In former scenario, this error will occur when you have created a new project using npm new command and are ready to deploy it. But once you run the command ng serve, you are presented with this error and the below stacktrace.

 

Cannot find module stacktrace

 

How to resolve

Follow the below steps to resolve this error.

  1. Update Angular cli using command npm update -g @angular/cli
  2. Navigate to your application folder and open package.json file using a text editor.
  3. Search for the property @angular/cli under devDependencies. It will have the value of form “1.6.0”(just an example).
  4. Change this property to “^1.6.0”. Prepend the property value with ^(caret).
  5. At the command prompt, run npm update

After the command execution completes, go ahead and run ng server, the error should be gone.

Once angular cli version is updated, you will also notice it being updated in package.json file. Open it and see.

In some cases, running the following command may also work

npm install @angular-devkit/core –save-dev

Using --save-dev option adds the package to devDependencies section of package.json file.

What does the caret(^) do ?

If caret is placed before a dependency version in package.json file and we run npm update, then npm installs the latest minor or patch version of this dependency. Example, if there is a dependency in package.json with version “^4.5.0”, then running npm update will install version 4.5.1 or 4.6.0 or whichever is the latest other than these.

 

sdasdasd

Leave a Reply