【问题标题】:Angular2 Build: Cannot find name 'Promise' only in Visual StudioAngular2 Build:仅在 Visual Studio 中找不到名称“Promise”
【发布时间】:2016-10-17 23:53:39
【问题描述】:

我开始使用 Angular2 并按照此处的快速入门:https://angular.io/guide/quickstart

当我执行 npm install 时它似乎工作正常,但我想在 Visual Studio 中运行它,我将在 Asp.Net/C# 而不是 NodeJS 中制作。

当我在 VS 中构建解决方案时,我得到了这个:

我认为在 nodejS 中它可以工作,因为在 package.json 我们有这个:

"postinstall": "typings install",

整个包.json

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common": "2.0.0-rc.2",
    "@angular/compiler": "2.0.0-rc.2",
    "@angular/core": "2.0.0-rc.2",
    "@angular/http": "2.0.0-rc.2",
    "@angular/platform-browser": "2.0.0-rc.2",
    "@angular/platform-browser-dynamic": "2.0.0-rc.2",
    "@angular/router": "2.0.0-rc.2",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.2",
    "systemjs": "0.19.27",
    "core-js": "^2.4.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "^0.6.12",
    "angular2-in-memory-web-api": "0.0.12",
    "bootstrap": "^3.3.6"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.2.0",
    "typescript": "^1.8.10",
    "typings": "^1.0.4"
  }
}

但问题是我使用的是 Visual Studio。如何在不使用 npm start

的情况下构建解决方案并使其运行

【问题讨论】:

  • 看起来 ES6 或打字稿代码使其运行时无法解释这一点。这可能意味着您需要填充一些东西(例如,导入 core-js 来填充很多东西)。或者您缺少构建步骤(例如,将 typescript 编译为 es5)。
  • 我没有任何构建步骤。我粘贴了来自 Angular 的代码。我再次强调它在使用 npm start 的 Node 中有效,但在构建解决方案时在 Visual 中无效。
  • “Promise”对于 JS 来说相对较新,它可能在您的 NodeJS 运行时中,但不在 Visual Studio 使用的运行时中。我不熟悉 VS,所以我不确定它在内部运行什么,但也许可以配置?

标签: javascript angularjs node.js typescript angular


【解决方案1】:

我认为你必须使用 es6-shim 来消除这些错误。试试这个:

typings install dt~es6-shim --save --global

这解决了我的问题。

【讨论】:

  • 我必须先安装类型:npm install typings -g 但此建议在此之后有效
  • 没错。您需要先通过 npm 安装类型,然后才能将任何类型添加到项目中。
猜你喜欢
  • 2017-02-13
  • 2016-10-03
  • 2017-02-01
  • 2016-04-02
  • 1970-01-01
  • 2016-11-17
  • 2017-09-23
  • 1970-01-01
  • 2016-07-04
相关资源
最近更新 更多