error TS2307: Cannot find module '@angular/core'
This problem apparently was being caused by the CDK and material modules of angular. I don't exactly know how it happend but I fixed it.
I fixed it by following an answer in this github issue: https://github.com/angular/material2/issues/8306
Solution
To fix this issue you have to run the following commands:
npm install --save @angular/material @angular/cdk
rm -rf node_modules
npm install
I see that some solutions are radical, I would not to try that in the first place. My solution was not radical, and it did the job.
I had the problem too, I did a simple
npm update
This was what came out:
$> npm update
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ [email protected]
+ [email protected]
added 2 packages from 6 contributors and audited 38996 packages in 13.315s
found 0 vulnerabilities
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ @types/[email protected]
updated 1 package and audited 38996 packages in 12.972s
found 0 vulnerabilities
And it solved the problem.
In order to fix this issue you have to update to Angular CLI version, as @angular cdk 6.0
requires @angular core 6.0 version
(updated version). Try to use updated version for both CLI and material/CDK
Follow these steps:-
npm uninstall -g @angular/cli
npm cache verify
if npm
version is less than 5 then use npm cache clean
npm install -g @angular/cli@latest
then create new angluar/cli
project after that install @angular/material
and @angular/cdk
.
I hope this will solve your problem.
For me problem got resolved when I make sure that @angular/material
, @angular/ckd
and @angular/animations
versions are compatible with @angular/core
version. Just edit package.json
.
In my case:
"@angular/core": "^7.2.15",
"@angular/animations": "^7.2.15",
"@angular/material": "^7.3.3",
"@angular/cdk": "^7.3.7",