首页 > 解决方案 > Cannot find name 'MediaQueryListEventMap' when I compile my angular project

问题描述

Here is the error infos when I build the project:

ERROR in node_modules/@angular/flex-layout/core/typings/match-media/mock/mock-match-media.d.ts(83,38): error TS2304: Cannot find name 'MediaQueryListEventMap'.
node_modules/@angular/flex-layout/core/typings/match-media/mock/mock-match-media.d.ts(83,99): error TS2304: Cannot find name 'MediaQueryListEventMap'.
node_modules/@angular/flex-layout/core/typings/match-media/mock/mock-match-media.d.ts(84,41): error TS2304: Cannot find name 'MediaQueryListEventMap'.
node_modules/@angular/flex-layout/core/typings/match-media/mock/mock-match-media.d.ts(84,102): error TS2304: Cannot find name 'MediaQueryListEventMap'.
node_modules/@angular/flex-layout/core/typings/match-media/mock/mock-match-media.d.ts(95,67): error TS2304: Cannot find name 'MediaQueryListEvent'.
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts(29,38): error TS2304: Cannot find name 'MediaQueryListEventMap'.
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts(29,99): error TS2304: Cannot find name 'MediaQueryListEventMap'.
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts(30,41): error TS2304: Cannot find name 'MediaQueryListEventMap'.
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts(30,102): error TS2304: Cannot find name 'MediaQueryListEventMap'.
node_modules/@angular/flex-layout/core/typings/match-media/server-match-media.d.ts(56,67): error TS2304: Cannot find name 'MediaQueryListEvent'.

I leave this project for quite a while. Maybe there is something wrong with the node modules updates, But I don't know how to fix it, here is the package.json:

"dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/flex-layout": "^7.0.0-beta.23",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/material": "^6.4.0",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "core-js": "^2.5.4",
    "font-awesome": "^4.7.0",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@angular-devkit/build-angular": "~0.6.8",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.8",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }

To be honest, I am very upset about the angular updating. Every time I try to 'npm install', I always run into some problems. Are there any better ways to deal with that. Thank you very much!

标签: angularnpm-install

解决方案


我遇到了同样的问题,所以我尝试了

ng update --all

但它给了我

                  Package "@angular/compiler-cli" has an incompatible peer dependency to "typescript" (requires ">=3.1.1 <3.3", would install "3.3.3").
                  Package "@angular/compiler-cli" has an incompatible peer dependency to "typescript" (requires ">=3.1.1 <3.3", would install "3.3.3")
Incompatible peer dependencies found. See above.

这对我有用,虽然很粗糙:

ng update --all --force
npm install typescript@">=3.1.1 <3.3.0"

推荐阅读