Skip to content

standalone components: rebuild needed to avoid false positive NG2012 #45819

@cexbrayat

Description

@cexbrayat

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

No, this is about standalone components

Description

Consider a simple standalone application with a standalone AppComponent, using a standalone HelloComponent.
On the first ng serve or ng build (or after a ng cache clean), the CLI throws an NG2012 error

🔬 Minimal Reproduction

This is consistently reproducible on this small reproduction: https://github.com/cexbrayat/standalone

npm i
ng serve

It also happens after every ng cache clean followed by ng serve, or when working and adding new components.

Saving the component again usually triggers a new rebuild that removes the issue.

🔥 Exception or Error


Error: src/app/app.component.ts:10:27 - error NG2012: Component imports must be standalone components, directives, pipes, or must be NgModules.

10   imports: [CommonModule, HelloComponent]
                             ~~~~~~~~~~~~~~

🌍 Your Environment


Angular CLI: 14.0.0-next.12
Node: 16.14.2
Package Manager: npm 6.14.16
OS: darwin arm64

Angular: 14.0.0-next.15
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1400.0-next.12
@angular-devkit/build-angular   14.0.0-next.12
@angular-devkit/core            14.0.0-next.12
@angular-devkit/schematics      14.0.0-next.12
@angular/cli                    14.0.0-next.12
@schematics/angular             14.0.0-next.12
rxjs                            7.5.5
typescript                      4.6.4

Anything else relevant?

This might of course be an issue with the compiler itself, but as the cache is seemingly involved, I thought it was best to open the issue here and let you transfer it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: compilerIssues related to `ngc`, Angular's template compilercross-cutting: standaloneIssues related to the NgModule-less worldstate: has PR

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions