导入MdSelectModule会导致角度构建失败

时间:2017-05-21 18:51:45

标签: angular angular-material2

当我尝试导入MdSelectModule角度时,我面临很多构建错误:

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

以下是package.json的内容:

 {
  "name": "sbmclient",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^4.0.0-beta.3",
    "@angular/compiler": "^4.0.0-beta.3",
    "@angular/core": "^4.0.0-beta.3",
    "@angular/forms": "^4.0.0-beta.3",
    "@angular/http": "^4.0.0-beta.3",
    "@angular/material": "^2.0.0-beta.5",
    "@angular/platform-browser": "^4.0.0-beta.3",
    "@angular/platform-browser-dynamic": "^4.0.0-beta.3",
    "@angular/router": "^4.0.0-beta.3",
    "core-js": "^2.4.1",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^2.3.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.28.3",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "~4.0.13",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "^2.0.10"
  }
}

构建结果报告了很多这样的错误:

    ERROR in D:/.../node_modules/@angular/material/typings/core/overlay/scroll/scrollable.d.ts (1,49): Mo
dule '"D:/.../node_modules/@angular/core/index"' has no exported member 'Renderer2'.

ERROR in D:/.../node_modules/@angular/material/typings/core/overlay/scroll/scroll-dispatcher.d.ts (10
,42): Initializers are not allowed in ambient contexts.

ERROR in D:/.../node_modules/@angular/material/typings/core/overlay/overlay-directives.d.ts (1,78): M
odule '"D:/.../node_modules/@angular/core/index"' has no exported member 'Renderer2'.

我的包裹文件有什么问题吗?

1 个答案:

答案 0 :(得分:1)

基本上问题是 Renderer2 仅存在于Angular 4.0.0 rc.1,您使用的是Angular 4.0.0 beta 3

此外,它提到了here,因为版本Angular Material 2 (beta 3)依赖于Angular 4.0.0并且你使用 Material2 beta 5 Angular 4.0.0 beta 3 。因此,它可能无效,因为您可以在Angular的 CHANGELOG (上面的链接)中看到, Renderer2 之前被称为 RendererV2 rc.1版本)。

解决方案:将@angular/* 个套餐更新到最新版本(包括@angular/compiler-cli〜这真的很旧〜)。