0

I have been banging my head for almost 10 hours on this but cannot resolve.

I have created a new Angular project which when I serve runs fine but as soon as I install and try to import material module, the compiler starts throwing error as

error TS2307: Cannot find module '@angular/core'.

This error goes away as I remove the import statement from my app module

I have tried reinstalling node, @angular/cli and all the packages but it does not work.

If it helps, package.json has

{
  "name": "firebase",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.2.8",
    "@angular/common": "~8.2.8",
    "@angular/compiler": "~8.2.8",
    "@angular/core": "~8.2.8",
    "@angular/flex-layout": "^8.0.0-beta.27",
    "@angular/forms": "~8.2.8",
    "@angular/material": "^8.2.1",
    "@angular/platform-browser": "~8.2.8",
    "@angular/platform-browser-dynamic": "~8.2.8",
    "@angular/router": "~8.2.8",
    "hammerjs": "^2.0.8",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.6",
    "@angular/cli": "~8.3.6",
    "@angular/compiler-cli": "~8.2.8",
    "@angular/language-service": "~8.2.8",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}

Happy to provide whatever information is needed.

1
  • what is your baseUrl in tsconfig.json? Commented Sep 28, 2019 at 13:14

1 Answer 1

1

I remember similar thing caused by angular cdk, can you try the following commands?

npm install --save @angular/material @angular/cdk
rm -rf node_modules
npm install
Sign up to request clarification or add additional context in comments.

4 Comments

inside my project directory?
windows or what os ? just remove node modules and do npm install
doing just npm install inside my project directory solved it. Can you please elaborate your answer why this might have happened despite of reinstalling everything?
most likely it could be reference node_modules package missed in the angular project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.