Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Could not resolve module @angular/core

I am trying to run an angular 4 application but i keep getting this error

ERROR in Could not resolve module @angular/core

There are no other errors. No dependency errors nothing. @angular/core exists in the node_modules folder. I have tried with @angular/cli installed and without but no effect on this error. I am not sure how to resolve this. It occurs in my amazon ec2 machine but not in my local Mac machine. The versions of the libraries are all the same.

Any help will be appreciated. Thanks.

like image 880
sushmit sarmah Avatar asked Nov 10 '17 11:11

sushmit sarmah


People also ask

How to resolve Cannot find module error in Angular?

Solution 1: Delete node_modules folder and run npm install But our local Angular application will have older versions of packages installed in node_modules folder. So delete the node_modules folder manually from the application directory. After that clear the cache using npm cache clean --verify .

How to fix Angular core error?

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.

Could not resolve dependency npm err peer Angular Common 11.0 0?

To fix Unable to resolve dependency tree error in Angular while installing npm packages follow the below steps. Run npm install --save --legacy-peer-deps instead of npm install command. Another way is delete node_modules folder and package_lock.


2 Answers

If anyone still facing such issue-

Your package.json may have been corrupt. Follow the below steps:

  1. Delete node_module folder.
  2. Clean/clear the cache. To clear the cache, run the below command.

    npm cache clean --force

  3. Install angular/core library again (specific version of your application).

    npm i @angular/core

  4. Again run npm install
like image 165
Neeraj Shende Avatar answered Sep 28 '22 12:09

Neeraj Shende


What may cause such issue is caused by an incorrect TypeScript configuration.

Make sure your tsconfig.json has moduleResolution set to "node" (rather than e.g. "classic").

like image 24
Guus Avatar answered Sep 28 '22 13:09

Guus