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

新手上路,请多包涵

我刚刚使用 此处 找到的 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。

我知道这些可能在教程的上下文中可以通过将 node 或 npm 回滚到与教程相关的版本来解决。我想我更愿意解释如何使教程中的代码与当前版本的 node.js 相关。

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

原文由 Blind Fish 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.2k
2 个回答

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

我想知道您是否在 tsconfig.json 文件中正确指定了 moduleResolution 属性:

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

原文由 Thierry Templier 发布,翻译遵循 CC BY-SA 3.0 许可协议

对我来说,这是 VSCode 编辑器的问题。只需重新打开编辑器即可解决它

原文由 Sudhakar 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题