node.js 没有导出的成员/节点模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38900357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No Exported Member / Node Modules
提问by Blind Fish
I am just starting Angular 2 / Typescript using the 5 Minute Quickstart found here. I've run into what looks to be a common problem, but maybe a bit different. I am encountering all sorts of "No Exported Member" problems. Examples:
我只是使用此处找到的 5 分钟快速入门来启动 Angular 2/Typescript 。我遇到了看起来很常见的问题,但可能有点不同。我遇到了各种“无导出成员”问题。例子:
From app.module.ts:
来自 app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
Returns
退货
...node_modules/@angular2/core/index" has no exported member 'NgModule'.
and
和
...@angular/platform-browser/index" has no exported member 'BrowserModule'.
And from main.ts:
来自 main.ts:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
throws:
抛出:
...@angular/platform-browser-dynamic/index" has no exported member 'platformBrowserDynamic'.
I am running node version 4.4.7 and npm version 3.10.5.
我正在运行节点版本 4.4.7 和 npm 版本 3.10.5。
I understand that these are probably resolvable in the context of the tutorial by rolling back node or npm to version relevant to the tutorial. I guess what I would prefer to have is an explanation of how to make the code from the tutorial relevant to the current versions of node.
我知道这些可能可以在教程的上下文中通过将 node 或 npm 回滚到与教程相关的版本来解决。我想我更喜欢解释如何使教程中的代码与当前版本的 node.js 相关。
ETA: These errors occur at compilation, not execution.
ETA:这些错误发生在编译时,而不是执行时。
采纳答案by Thierry Templier
The NgModuleclass is exported from the node_modules/@angular/core/src/metadata.d.tsfile through the node_modules/@angular/core/index.d.tsone.
本NgModule类是从导出的node_modules/@angular/core/src/metadata.d.ts文件经过node_modules/@angular/core/index.d.ts一个。
I wonder if you specify correctly the moduleResolutionproperty in your tsconfig.jsonfile:
我想知道您是否正确指定了文件中的moduleResolution属性tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node", // <-----
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
回答by Sudhakar
For me it was VSCode editor issue. Simply reopening the editor resolved it
对我来说,这是 VSCode 编辑器问题。只需重新打开编辑器即可解决
回答by Sma Ma
please update all your @angular dependencies in package.json to at least "2.0.0-rc.5"
请将 package.json 中的所有 @angular 依赖项更新为至少“2.0.0-rc.5”
after that verify your application bootstrap in main.ts.
之后在 main.ts 中验证您的应用程序引导程序。
according to changelog of 2.0.0-rc.5 there is a change of bootstrap your app. or see also updated tutorial guide https://angular.io/guide/quickstart.
根据 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);
回答by Akhil A
In package.json file, all dependencies which are using rc.4, replace them by rc.5. Then it will work.
在 package.json 文件中,所有使用 rc.4 的依赖项,替换为 rc.5。然后它会起作用。
回答by Naveen Nirban Yadav
Editor cache issue, its common in IDE's Android Studio,VS Code & Atom. Restarting the editor/IDE will help.
编辑器缓存问题,在 IDE 的 Android Studio、VS Code 和 Atom 中很常见。重新启动编辑器/IDE 会有所帮助。

