简体   繁体   English

角度2:找不到模块“角度2 /核心”

[英]Angular 2: Cannot find module 'angular2/core'

I'm having a problem with Angular 2 + Typescript, whenever I try to gulp build it shows me the same errors, I have tried everything including putting the <reference> tags in the files. 我在使用Angular 2 + Typescript时遇到问题,每当尝试吞噬它时,它就会向我显示相同的错误,我尝试了所有操作,包括将<reference>标记放入文件中。 What to do? 该怎么办?

 (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 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);
  }
}

I had the same issue before because of System.config.js misconfiguration. 由于System.config.js配置错误,我之前遇到过同样的问题。 Try to check if the configuration is correct. 尝试检查配置是否正确。

Configure External Web tools 配置外部Web工具

Configure Visual Studio to use the global external web tools instead of the tools that ship with Visual Studio: 将Visual Studio配置为使用全局外部Web工具,而不是Visual Studio附带的工具:

•Open the Options dialog with Tools | •使用工具|打开选项对话框。 Options 选件

•In the tree on the left, select Projects and Solutions | •在左侧的树中,选择“项目和解决方案” | External Web Tools. 外部Web工具。

•On the right, move the $(PATH) entry above the $(DevEnvDir) entries. •在右侧,将$(PATH)条目移至$(DevEnvDir)条目上方。 This tells Visual Studio to use the external tools (such as npm) found in the global path before using its own version of the external tools. 这告诉Visual Studio在使用自己的外部工具版本之前,请使用在全局路径中找到的外部工具(例如npm)。

•Click OK to close the dialog. •单击“确定”关闭对话框。

•Restart Visual Studio for this change to take effect. •重新启动Visual Studio,以使此更改生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM