can not find module “@angular/material”

前端 未结 7 707
余生分开走
余生分开走 2021-01-31 02:47

I\'m using Angular 2. When I\'m trying to import \"@angular/material\" i\'m getting error for this. I\'m importing packages like:

import {MdDialog} from \"@angul         


        
7条回答
  •  一向
    一向 (楼主)
    2021-01-31 03:08

    I followed each of the suggestions here (I'm using Angular 7), but nothing worked. My app refused to acknowledge that @angular/material existed, so it showed an error on this line:

    import { MatCheckboxModule } from '@angular/material';
    

    Even though I was using the --save parameter to add Angular Material to my project:

    npm install --save @angular/material @angular/cdk
    

    ...it refused to add anything to my "package.json" file.

    I even tried deleting the package-lock.json file, as some articles suggest that this causes problems, but this had no effect.

    To fix this issue, I had to manually add these two lines to my "package.json" file.

    {
        "devDependencies": {
            ...
            "@angular/material": "~7.2.2",
            "@angular/cdk": "~7.2.2",
            ...
    

    What I can't tell is whether this is an issue related to using Angular 7, or if it's been around for years....

提交回复
热议问题