sushmit sarmah
sushmit sarmah

Reputation: 7748

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.

Upvotes: 11

Views: 14040

Answers (3)

Lucas Lombardi
Lucas Lombardi

Reputation: 129

Had the same problem, solved changing the tsconfig, not sure that it will helps, using this now,:

{
    "compileOnSave": false,
    "compilerOptions": {
      "baseUrl": "./",
      "outDir": "./dist/out-tsc",
      "sourceMap": true,
      "declaration": false,
      "module": "es2015",
      "moduleResolution": "node",
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "target": "es5",
      "typeRoots": [
        "node_modules/@types"
      ],
      "lib": [
        "es2017",
        "dom"
      ]
    }
  }

Upvotes: 2

Guus
Guus

Reputation: 11

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").

Upvotes: 0

Neeraj Shende
Neeraj Shende

Reputation: 358

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

Upvotes: 4

Related Questions