没有导出的成员/节点模块

我正在使用在这里find的5分钟快速入门启动Angular 2 / Typescript。 我遇到了一个看起来很常见的问题,但也许有点不同。 我遇到各种“无出口成员”的问题。 例子:

来自app.module.ts:

import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; 

返回

 ...node_modules/@angular2/core/index" has no exported member 'NgModule'. 

 ...@angular/platform-browser/index" has no exported member 'BrowserModule'. 

从main.ts:

 import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 

抛出:

 ...@angular/platform-browser-dynamic/index" has no exported member 'platformBrowserDynamic'. 

我正在运行节点版本4.4.7和npm版本3.10.5。

我明白,这些可能在本教程的上下文中通过回滚节点或npm到与本教程相关的版本来解决。 我想我想要的是解释如何使教程中的代码与当前版本的节点相关。

ETA:这些错误发生在编译,而不是执行。

NgModule类是通过node_modules/@angular/core/index.d.tsnode_modules/@angular/core/src/metadata.d.ts文件导出的。

我想知道,如果你正确指定您的tsconfig.json文件中的tsconfig.json属性:

 { "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", // <----- "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false } } 

对我来说这是VSCode编辑器的问题。 简单地重新打开编辑器解决了它

请将package.json中的所有@angular依赖项至less更新为“2.0.0-rc.5”

之后在main.ts中validation你的应用程序引导。

根据2.0.0-rc.5的更新日志,你的应用程序有一个改变。 或者参阅更新的教程指南https://angular.io/guide/quickstart

 import {NgModule} from '@angular/core'; @NgModule({ declarations: […], // directives, components, and pipes owned by this NgModule imports: [BrowserModule], providers: […], // additional providers bootstrap: [MainComponent], }) class MyAppModule {} // Ahead of Time compile import {platformBrowser} from '@angular/platform-browser'; platformBrowser().bootstrapModuleFactory(MyAppModuleNgFactory); // JIT compile long form import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; platformBrowserDynamic().bootstrapModule(MyAppModule); 

在package.json文件中,所有使用rc.4的依赖关系都被rc.5replace。 然后它会工作。