Error: Could not resolve module @angular/core

Viewed 8363

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.

3 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

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"
      ]
    }
  }

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

Related