【问题标题】:Angular2 Failing to update to RC7 - zone.js & reflect-metadataAngular2 无法更新到 RC7 - zone.js & reflect-metadata
【发布时间】:2017-01-25 17:17:50
【问题描述】:

我正在尝试让我的应用程序使用 Angular 的新 RC7 运行,但我似乎无法完成它,因为控制台喊道:

Promise rejection: Zone.assertZonePatched is not a function      angular2-polyfills.js:489

当这个不知何故消失时,会弹出这个:

Reflect.getMetadata is not a function (..)                                core.umd.js:472

看起来实现发生了变化,虽然我 npm installed 一切从头开始,但我的没有更新,更新我的 package.json 如下:

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "build": "webpack",
    "start": "webpack-dev-server",
    "typings": "typings",
    "postinstall": "typings install"
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common": "2.0.0-rc.7",
    "@angular/compiler": "2.0.0-rc.7",
    "@angular/core": "2.0.0-rc.7",
    "@angular/forms": "2.0.0-rc.7",
    "@angular/http": "2.0.0-rc.7",
    "@angular/platform-browser": "2.0.0-rc.7",
    "@angular/platform-browser-dynamic": "2.0.0-rc.7",
    "@angular/router": "3.0.0-rc.3",
    "@angular/upgrade": "2.0.0-rc.7",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "^0.6.21",
    "angular2-in-memory-web-api": "0.0.19",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.3",
    "angular2": "2.0.0-beta.17",
    "angular2-apollo": "^0.4.6",
    "apollo-client": "^0.4.13",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.35.1",
    "moment": "^2.14.1",
    "source-map-loader": "^0.1.5"
  },
  "devDependencies": {
    "ts-loader": "^0.8.2"
  }
}

index.html:(我也试过参考unpkg.com的包,没有成功)

<html>

  <head>
    <title>My App</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.3/css/bootstrap.min.css"
          integrity="sha384-MIwDKRSSImVFAZCVLtU0LMDdON6KVCrZHyVQQj6e8wIEJkW4tvwqXrbMIya1vriY" crossorigin="anonymous">
    <link rel="stylesheet" href="style.css">

    <!-- 1. Load libraries -->
    <!-- IE required polyfills, in this exact order -->
    <script src="node_modules/es6-shim/es6-shim.min.js"></script>

    <script src="https://www.atlasestateagents.co.uk/javascript/tether.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.3/js/bootstrap.min.js"
            integrity="sha384-ux8v3A6CPtOTqOzMKiuo3d/DomGaaClxFYdCu2HPMBEkf6x2xiDyJ7gkXU0MWwaD" crossorigin="anonymous"></script>

    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
  </head>

  <!-- 3. Display the application -->
  <body>
    <my-app>Loading...</my-app>
  </body>

  <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
  <script src="dist/bundle.js"></script>
</html>

知道如何解决这个问题吗?

提前致谢! :)

【问题讨论】:

  • 您的package.json 属于Angular2.0 版本。
  • @micronyks 你是什么意思?
  • 你正在安装 Angular2.0(最近发布的包)如果你正在寻找 RC7 包,请参考 - stackoverflow.com/questions/39496055/… 我已经展示了带有 systemjs 而不是 webpack 的 RC7 包。
  • @micronyks 嘿,更新了我的 package.json,这仍然会产生同样的错误,有什么想法吗?
  • @micronyks 已解决,请参阅下面的答案

标签: javascript angular zonejs reflect-metadata


【解决方案1】:

注意事项:

  • 根据 package.json,您使用的是 Angular2.0.0 您不需要 angular2-polyfills.js
  • 从 package.json 中删除 "angular2": "2.0.0-beta.17"
  • 从 index.html

    中删除 angular2-polyfills.js
    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    

事实上,如果您在 node_modules 下有 angular2 文件夹,则删除该文件夹。最新的 angular2 包将在 node_modules 下的 @angular 文件夹中提供。

【讨论】:

  • 你基本上是在说我应该从我的package.json 中删除 angular2 的依赖,然后重新npm i? (将我的 package.json 依赖项更新为使用 -rc.7 的依赖项)
  • 而且 angular2 包似乎不存在于 node_modules 下的 @angular 中:|
  • 清理 node_modules 文件夹,然后运行 ​​npm install 它会在 node_modules 下的 @angular 中为您提供包。
  • 获得最新包后,从index.html 中删除angular2-polyfills.js,然后运行应用程序。
  • @sanket 这对我不起作用。我已经在使用 angular 2.0.0,并且我的 package.json 和 index.html 中都没有使用任何 polyfills.js。所以我不确定为什么我仍然收到“Reflect.getMetadata is not a function”错误。
猜你喜欢
  • 2017-01-29
  • 1970-01-01
  • 2016-03-22
  • 2016-04-29
  • 2017-01-22
  • 2021-06-29
  • 1970-01-01
  • 1970-01-01
  • 2021-12-03
相关资源
最近更新 更多