Angular 2:找不到模块'angular2 / core'

时间:2016-07-19 18:15:38

标签: javascript typescript angular gulp gulp-typescript

我遇到了Angular 2 + Typescript的问题,每当我尝试吞下构建它会向我显示相同的错误时,我已经尝试了所有内容,包括放置< reference>文件中的标签。怎么办?

(7,26): error TS2307: Cannot find module 'rxjs/Rx'./Users/macbook/workspace/rss/src/app/services/rootscope.ts
(8,46): error TS2307: Cannot find module 'angular2/core'./Users/macbook/workspace/rss/src/app/services/rootscope.ts
(17,48): error TS2304: Cannot find name 'Observer'./Users/macbook/workspace/rss/src/app/services/api.ts
(6,26): error TS2307: Cannot find module 'angular2/core'./Users/macbook/workspace/rss/src/app/services/api.ts
(7,27): error TS2307: Cannot find module 'angular2/http'./Users/macbook/workspace/rss/src/app/services/api.ts
(15,13): error TS2339: Property 'http' does not exist on type 'API'./Users/macbook/workspace/rss/src/app/services/api.ts
(19,20): error TS2339: Property 'http' does not exist on type 'API'./Users/macbook/workspace/rss/src/app/services/api.ts
(23,20): error TS2339: Property 'http' does not exist on type 'API'../src/app/app.ts
(6,25): error TS2307: Cannot find module 'angular2/platform/browser'../src/app/app.ts
(7,25): error TS2307: Cannot find module 'angular2/core'../src/app/app.ts
(8,47): error TS2307: Cannot find module 'angular2/http'. 

rootscope.ts

/// <reference path="../../../node_modules/reflect-metadata/reflect- metadata.d.ts" />
/// <reference path="../../../node_modules/angular2/typings/browser.d.ts" />
/// <reference path="../../../node_modules/angular2/core.d.ts" />
/// <reference path="../../../node_modules/angular2/http.d.ts" />
/// <reference path="../../../node_modules/rxjs/Rx.d.ts" />

import {Observable} from "rxjs/Rx";

import {Injectable,EventEmitter,Output} from "angular2/core";

@Injectable()
export class ROOT_SCOPE {
  data: any;
  dataChange: Observable<any>;
  @Output dataChangeObserver: EventEmitter=new EventEmitter();

  constructor() {
    this.dataChange = new Observable((observer:Observer) => {
      this.dataChangeObserver = observer;
    });
  }

  set(data:any) {
    this.data = data;
    this.dataChangeObserver.next(this.data);
  }
}

2 个答案:

答案 0 :(得分:0)

由于System.config.js配置错误,我之前遇到了同样的问题。 尝试检查配置是否正确。

答案 1 :(得分:-1)

配置外部网络工具

将Visual Studio配置为使用全局外部Web工具而不是Visual Studio附带的工具:

•使用“工具”打开“选项”对话框选项

•在左侧的树中,选择“项目和解决方案”|外部Web工具。

•在右侧,将$(PATH)条目移到$(DevEnvDir)条目上方。这告诉Visual Studio在使用自己的外部工具版本之前使用全局路径中的外部工具(例如npm)。

•单击“确定”关闭对话框。

•重新启动Visual Studio以使此更改生效。