键入角度无法找到名称错误

时间:2016-08-20 09:25:59

标签: node.js express angular typescript-typings

我得到"找不到名字'承诺'尝试运行angular2-express app" npm run develop"

时出错
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"
      }
    }

main.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 {}

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

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

如果您有经验,则无法找到名称错误。,大多数情况下您已更改基本设置中的某些文件,或者您可能未成功完成节点包安装。 Angular2不再使用打字包。

溶液:

克隆以下存储库https://github.com/angular/quickstart 在项目目录中运行npm install并确保它成功完成 现在将您的应用程序项目文件夹复制并配置到克隆的新文件夹中,现在这将完美地运行。

答案 2 :(得分:0)

您可以尝试将"lib": ["es6"]添加到tsconfig.json配置文件中。如果您使用的是浏览器符号,例如窗口等,您也可以尝试"lib": ["es6", "dom"]