简体   繁体   中英

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

I have a problem with running angular 2 application. 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:

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.

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.

Hope that helps!

Thanks everybody for comments and help. The problem was that in other file I had dependency to 'q-io/fs' package. Removing that, angular started without any additional manipulations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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