How to resolve The _AppComponent component is not marked as standalone, but Angular expects to...

Discussão em 'Angular' iniciado por Janvi, Janeiro 29, 2025.

  1. Janvi

    Janvi Guest

    I was migrating from standalone component to module based where I changed and even tried to remove standalone in the decorator in the appcomponent, and in main.ts file I imported platformdynamic and bootstrapModule to the main module and in module file I declared the appcomponent and bootstrap it still it's generating runtime error 'Internal server error: NG0907: The _AppComponent component is not marked as standalone, but Angular expects to have a standalone component here. Please make sure the _AppComponent component has the standalone: true flag in the decorator.'

    Here is the relevant code:

    app.module.ts file:

    import { NgModule } from "@angular/core";
    import { BrowserModule } from "@angular/platform-browser";
    import { AppComponent } from "./app.component";
    import { HeaderComponent } from "./header/header.component";
    import { UserComponent } from "./user/user.component";
    import { TasksComponent } from "./tasks/tasks.component";

    @NgModule({

    declarations: [AppComponent],
    bootstrap: [AppComponent],
    imports:[BrowserModule, HeaderComponent, UserComponent, TasksComponent]
    })
    export class AppModule{

    }


    app.component.ts file:

    import { Component } from '@angular/core';
    import { DUMMY_USERS } from "./dummy-users";

    @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrl: './app.component.css'

    })
    export class AppComponent {}


    main.ts file

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

    import { AppModule } from "./app/app.module";

    platformBrowserDynamic().bootstrapModule(AppModule).catch(err => console.error(err));

    Continue reading...

Compartilhe esta Página