Missing `standalone` components declared with `button[custom-button]` are not reported by the compiler
See original GitHub issueWhich @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
When standalone component is created with @Component({ selector: 'button[cv-button]'
it will be not reported during compile time
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/angular-standalone-uzrsmn?file=src%2Fmain.ts
Please provide the exception or error you saw
No message is displayed in Console about missing info, uncomment 59 line to make component work
Please provide the environment you discovered this bug in (run ng version
)
Angular CLI: 14.0.0
Node: 14.18.2
Package Manager: yarn 3.2.0
OS: win32 x64
Angular: 14.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1400.0
@angular-devkit/build-angular 14.0.0
@angular-devkit/core 14.0.0
@angular-devkit/schematics 14.0.0
@schematics/angular 14.0.0
rxjs 7.5.5
typescript 4.7.3
Anything else?
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Getting started with standalone components
Angular classes marked as standalone do not need to be declared in an NgModule (the Angular compiler will report an error if you...
Read more >Angular 14—Introducing Standalone Components
A standalone component is a type of component which is not part of any Angular module. Prior to Angular 14, usually when you...
Read more >Angular 14: Three Can't-Miss New Features
Standalone components don't need to be declared in a module. We can create our first standalone component using CLI command: ng g c...
Read more >Incorrect Angular "Missing or invalid component declaration in ...
When a component in module declarations is referenced through a field of a constant or static, the inspector incorrectly reports a missing declaration...
Read more >The Story Behind Angular Standalone Components
Angular classes marked as standalone do not need to be declared in an NgModule (the Angular compiler will report an error if you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was asked to copy and paste here the description of a duplicate issue I opened (#46661), so here it goes:
If a directive has an attribute selector and the attribute is used without square brackets, such as
routerLink="/users"
, and we forget to import the directive, or the module defining the directive, then the compiler doesn’t complain at all, and we end up with an unnoticed bug.When using NgModules, such a bug happens rarely, because you rarely forget to import the router module (for example) in your main or feature module. But when using standalone components, it’s much more frequent, because the import needs to be repeated on every component that needs the directive, and of course we tend to only import what’s absolutely needed.
After migrating two relatively small applications to standalone components, I’ve introduced such a bug, especially with routerLink, at least twice.
I understand why the compiler doesn’t complain, but this, IMHO, is a source of hard to detect bugs: I doubt most people have integration tests checking that each and every link in their components works as expected. And even at runtime, the bug goes unnoticed until you click on the link and realize it doesn’t work. Proposed solution
It would be nice to be able to activate some compiler option that would, for example, check that any non-standard HTML attribute used in a component (such as routerLink) matches with a known directive selector for that component.
Or to be able to provide a list of selectors or attributes that must be checked.
+💯 huge bug source… I’d love to see a strict build option that complains about any “unknown attribute”. This way we are sure that imports are not missing.
Rather than maintaining a list of all known html attributes (if that is the main concern/difficulty)… at least give us a “allowedAttributes: []” where we can specify which attributes are safe to ignore (do not require an import).