node.js - 输入 Angular 找不到名称错误

标签 node.js express angular typescript-typings

我在尝试运行 angular2-express 应用“npm run develop”时遇到“找不到名称‘Promise’错误”

node_modules/@angular/common/src/directives/ng_class.d.ts(81,34):error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/common/src/facade/lang.d.ts(11,17): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/common/src/facade/lang.d.ts(12,17): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/common/src/facade/lang.d.ts(67,59): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/common/src/pipes/async_pipe.d.ts(41,38): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_init.d.ts(16,18): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(99,88): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(134,67): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(150,109): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(202,67): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(204,109): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(236,42): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(331,33): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(100,41): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(101,22): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(102,25): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/core/src/facade/lang.d.ts(11,17): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/lang.d.ts(12,17): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/core/src/facade/lang.d.ts(67,59): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/linker/compiler.d.ts(47,76): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/linker/compiler.d.ts(62,57): error TS2304: Cannot find name 'Promise'.

.....
.....

这是几个文件的内容

package.json

{
  "name": "angular2-express-starter",
  "version": "1.0.0",
  "description": "Starter application of Angular2 on Express",
  "main": "gulpfile.js",
  "private": true,
  "scripts": {
    "develop": "concurrently \"tsc -w -p ./server\" \"tsc -w -p ./client\" \"nodemon ./server/bin/www\" ",
    "twc:client:w": "tsc -w -p ./client",
    "twc:server:w": "tsc -w -p ./server",
    "typings": "typings install",
    "bundle": "node tools/builder.js",
    "bundle:prod": "node tools/builder.js --prod",
    "postinstall": "typings install && tsc -p ./server"
  },
  "engines": {
    "node": ">= 5.4.1 < 6"
  },
  "author": "Vlado Tešanović",
  "license": "MIT",
  "dependencies": {
    "bcrypt": "^0.8.7",
    "body-parser": "~1.13.2",
    "cookie-parser": "~1.3.5",
    "express": "^4.13.4",
    "express-jwt": "^3.3.0",
    "jsonwebtoken": "^5.7.0",
    "jwt-simple": "*",
    "morgan": "*",
    "mysql": "^2.11.1",
    "serve-favicon": "~2.3.0",
    "typescript": "^1.8.10",
    "typings": "^1.3.2"
  },
  "devDependencies": {
    "@angular/common": "2.0.0-rc.5",
    "@angular/compiler": "2.0.0-rc.5",
    "@angular/core": "2.0.0-rc.5",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.5",
    "@angular/platform-browser": "2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "2.0.0-rc.5",
    "@angular/router": "^3.0.0-rc.1",
    "@angular/router-deprecated": "^2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.5",
    "angular2-in-memory-web-api": "0.0.15",
    "angular2-jwt": "^0.1.18",
    "concurrently": "^2.2.0",
    "core-js": "^2.4.1",
    "ng-semantic": "^1.0.33",
    "nodemon": "^1.9.1",
    "reflect-metadata": "^0.1.3",
    "retyped-bcrypt-tsd-ambient": "0.0.0-0",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.27",
    "systemjs-builder": "^0.15.17",
    "yargs": "^4.8.1",
    "zone.js": "^0.6.12"
  }
}

typings.json

{
    "globalDependencies": {
        "body-parser": "registry:dt/body-parser#0.0.0+20160619023215",
        "es6-collections": "registry:dt/es6-collections#0.5.1+20160316155526",
        "es6-promise": "registry:dt/es6-promise#0.0.0+20160614011821",
        "express": "registry:dt/express#4.0.0+20160708185218",
        "express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160715232503",
        "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
        "jquery": "registry:dt/jquery#1.10.0+20160704162008",
        "mime": "registry:dt/mime#0.0.0+20160316155526",
        "node": "registry:dt/node#6.0.0+20160720070758",
        "serve-favicon": "registry:dt/serve-favicon#0.0.0+20160316155526",
        "serve-static": "registry:dt/serve-static#0.0.0+20160606155157"
      },
      "dependencies": {
        "jsonwebtoken": "registry:npm/jsonwebtoken#5.5.4+20160208220328"
      }
    }

ma​​in.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule }              from './components/app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

app.ts

import { Component } from "@angular/core";
import { ROUTER_DIRECTIVES } from '@angular/router';
import { Header } from './header/header'
import { Footer } from './footer/footer'
import { UserService } from "../services/user.service";

@Component({
    directives: [ ROUTER_DIRECTIVES, Header, Footer ],
    selector: "app",
    templateUrl: "client/components/app.html",
    styles: [
        './rajd-theme.css'
    ]
})
export class App {
    constructor(private userService: UserService) {

    }
}

app.module.ts

import { NgModule }       from '@angular/core';
import { BrowserModule  } from '@angular/platform-browser';
import { FormsModule  } from '@angular/forms';
import { RouterModule  } from '@angular/router';

import { App }   from './app.ts';

@NgModule({
    declarations: [App],
    imports:      [
        BrowserModule,
        FormsModule,
        RouterModule
    ],
    bootstrap:    [App],
})
export class AppModule {}

请注意,我使用的是 angular rc5 和 NgModules。

最佳答案

我遇到了同样的问题,但我通过更改 tsconfig.json 中的 "target": "es2015" 设法解决了这个问题。我无法告诉您为什么这解决了我的问题,但它确实有效。

关于node.js - 输入 Angular 找不到名称错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39052516/

相关文章:

javascript - 如何在node js中发送curl的curl授权-u?

node.js - 无法使用express从nodejs请求对象访问文件

node.js - nodejs/express - 立即将标准输出流式传输到客户端

html - Angular 5 w/Angular Material 2 - 加载背景的最佳方式?

javascript - chart.js 中圆环图上的自定义数据位置

javascript - 这个例子中的 Angular *ngFor 究竟是如何工作的?

node.js - 使用 s3 api 删除 gcp bucket 对象

node.js - 如何在 Electron + Node -ffi-napi中获得正确的 native 内存地址

Node.js 控制台异步应用程序 "best practice"

node.js - Node (Express)文件导入到 Controller 中