简体   繁体   English

Angular2 引导程序错误:错误:没有 ExceptionHandler。 是否包括平台模块 (BrowserModule)?

[英]Angular2 bootstrap error: Error: No ExceptionHandler. Is platform module (BrowserModule) included?

I have a problem with running angular 2 application.我在运行 angular 2 应用程序时遇到问题。 During call of通话期间

import { PlatformRef } from '@angular/core/src/application_ref';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './components2/app.module';


const platform: PlatformRef = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

I have this error:我有这个错误: 在此处输入图片说明

This is weird error, because BrowserModule is included:这是一个奇怪的错误,因为包含 BrowserModule:

import { NgModule } from "@angular/core"
import { BrowserModule } from "@angular/platform-browser";
import { AppComponent } from "./app.component";
import { FormsModule } from "@angular/forms";

@NgModule({
    imports: [BrowserModule, FormsModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule {}

Thanks in advance.提前致谢。

Try to modify your main.ts file with below code.尝试使用以下代码修改 main.ts 文件。

import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app/';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

Note: Use latest angular-cli to create your project.注意:使用最新的angular-cli创建您的项目。

Hope that helps!希望有帮助!

Thanks everybody for comments and help.感谢大家的意见和帮助。 The problem was that in other file I had dependency to 'q-io/fs' package.问题是在其他文件中我依赖于 'q-io/fs' 包。 Removing that, angular started without any additional manipulations.去掉那个,angular 开始时没有任何额外的操作。

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

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