【问题标题】:Simplest angular2 setup with webpack使用 webpack 最简单的 angular2 设置
【发布时间】:2016-06-02 01:53:10
【问题描述】:

我正在阅读有关 Angular2 的 egghead.io 教程,但他们仍在使用测试版。我正在查看Angular2 Quickstart 的文档,它指向更新的候选版本,但我无法从 egghead.io 课程中获取 webpack 服务器来使用 angular2 包,我不是真的很确定挂断在哪里。

package.json:

  "devDependencies": {
    "html-webpack-plugin": "^2.9.0",
    "ts-loader": "^0.7.2",
    "typescript": "^1.7.3",
    "typings": "^0.6.8",
    "webpack": "^1.12.14",
    "webpack-dev-server": "^1.14.0"
  },
  "dependencies": {
    "@angular/common": "^2.0.0-rc.1",
    "@angular/compiler": "^2.0.0-rc.1",
    "@angular/core": "^2.0.0-rc.1",
    "@angular/http": "^2.0.0-rc.1",
    "@angular/platform-browser": "^2.0.0-rc.1",
    "@angular/platform-browser-dynamic": "^2.0.0-rc.1",
    "@angular/router": "^2.0.0-rc.1",
    "@angular/router-deprecated": "^2.0.0-rc.1",
    "@angular/upgrade": "^2.0.0-rc.1",
    "reflect-metadata": "^0.1.3",
    "rxjs": "^5.0.0-beta.8",
    "zone.js": "^0.6.12"
  }

我没有更改课程中提供的webpack.config.js

当我执行npm start(运行 webpack 服务器)时,我不断得到

Error during instantiation of NgZone! (ApplicationRef -> ApplicationRef_ -> NgZone).
Cannot read property 'fork' of undefined

这表明zone.fork 没有加载。我确实将我的vendor.ts 文件更新为:

import 'zone.js';
import 'reflect-metadata';

但我仍然遇到与上述相同的错误。如果我在console.log(zone.fork) 中包含一个简单的脚本标签,它会记录一个函数,所以似乎 zone.js 正在加载。我不确定为什么 Angular2 不会启动,或者我是否需要包含其他内容。

【问题讨论】:

  • 您是否尝试过擦除您的node_modules 并重新安装?这闻起来像是一个错误的部门悄悄潜入其中
  • 另外,小心地将你的 rxjs 版本提升到 angular 之外(peer 依赖于 rc0 中的 beta-6)。这很可能会很好,但如果不是,你会发现虫子从肠道深处爬出来。
  • @drewmoore 是的,我尝试过多次擦除和重新安装。我也试过beta.6,但我遇到了完全相同的问题。

标签: javascript angular webpack


【解决方案1】:

您正在导入

"rxjs": "^5.0.0-beta.8",

但是 rc.1 只兼容 beta.6

【讨论】:

  • 更新到.6,但这仍然产生同样的问题
猜你喜欢
  • 2017-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-09
  • 1970-01-01
  • 2017-05-26
相关资源
最近更新 更多