-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False Positive: 'QueryList' is imported from external module '@angular/core' but never used #710
Comments
Can you share your project files? |
Sorry, i cannot share ny project files. This issue is easily reproducible, just use the @ContentChildren with QueryList type. |
This won't cause a problem. It is because it is only being used as a type. |
I know this won’t cause a problem, that’s why i said in the title it is a false positive 😁 |
This is an issue with Angular Compiler. Have a look at this angular/angular#21280 |
Yes, but I don't see how the issue could be solved?!? After TypeScript compilation, the import is still there and then rollup is going to (tree?-)shake it out. I think a fix for that should be in tsc, because only tsc knows whether the symbol is being used as a compile-time type only or as a value at runtime. |
Atually with tsc compilation the import is dropped but with ngc it isn’t hence the Angular Compiler issue mentioned above. |
Ok. thanks for clarification. |
I get similar problem like this when using I tried using This warning message logged 2x to console is
Here is my component that makes compile warning.
The Clearly |
Also happens with TemplateRef, I'm using it as a type: And when compiling it says: |
I also am using a |
Same thing happens to me. I am using TemplateRef to reference to a modal // reference to the text area modal
@ViewChild('textAreaDialog') textAreaDialog: TemplateRef<any>; |
Same |
any progress here? |
Also looking for a solution... Any news ? |
Same problem with FormGroup imported from @angular/forms. Solved by workaround - creating instance of FormGroup in constructor:
The compiler no longer thinks FormGroup is not used. |
Same problem here with:
|
To all those commenting specific cases: This will happen with any Class you import then use only as a type definition. As already linked above this is a duplicate of: angular/angular#21280 |
Hi! This issue will gone if you will use For example: import { ChangeDetectionStrategy, Component, Input, ViewChild } from '@angular/core'
...
import type { ElementRef, NgZone, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core'
... It works nice for ng-packagr@10.0.0 |
This warning went away when I switched to Ivy builds and disabled tsconfig.js: "compilerOptions": {
--- "emitDecoratorMetadata": true,
},
"angularCompilerOptions": {
+++ "enableIvy": true
}, Admittedly this isn't (yet) a viable workaround if you're publishing libraries that need to be used by non-Ivy projects. |
Incidentally, warnings disappeared when I upgraded to Angular 10 (along with all other JS deps). I was going to implement @Semigradsky solution when I noticed that Angular 10 was just released. So I started by upgrading everything. And without any change in my own code, warnings disappeared. I did not investigate further to find out exactly which package upgrade solved this, but if you are in a position to upgrade Angular, you might want to try that first. |
Building off of what @PowerKiKi said. I got these issues when I added |
Just ignore this warning, that is the best solution :) |
this ticket is more than 3 years old and it's still happening ... I guess no one cares about a clean ci output anymore 🤷♂️ |
On the contrary, this issue should be closed as solved, because it is no longer reproducible with latest version. @karan-kang, @alxhub, could you please close this issue as solved ? Creating a new lib from scratch with: ng new my-workspace --create-application=false --strict
cd my-workspace/
ng generate library my-lib Replace the content of import {Component, ContentChildren, ElementRef, Inject, QueryList, ViewChild} from '@angular/core';
@Component({
selector: 'lib-my-lib',
template: `
<p>
my-lib works!
</p>
`,
styles: [],
})
export class MyLibComponent {
private window: Window;
@ContentChildren(MyLibComponent)
options: QueryList<MyLibComponent> | null = null;
@ViewChild('gmap') gmapElement: ElementRef | null = null;
constructor(@Inject('Window') myWindow: any) {
this.window = myWindow;
}
} And this will build correctly with zero warnings: $ ng build my-lib --prod
Building Angular Package
------------------------------------------------------------------------------
Building entry point 'my-lib'
------------------------------------------------------------------------------
✔ Compiling TypeScript sources through NGC
✔ Bundling to FESM2015
✔ Bundling to UMD
✔ Minifying UMD bundle
✔ Writing package metadata
ℹ Built my-lib
------------------------------------------------------------------------------
Built Angular Package
- from: /tmp/q/my-workspace/projects/my-lib
- to: /tmp/q/my-workspace/dist/my-lib
------------------------------------------------------------------------------ $ ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 11.2.12
Node: 14.16.1
OS: linux x64
Angular: 11.2.13
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1102.12
@angular-devkit/build-angular 0.1102.12
@angular-devkit/core 11.2.12
@angular-devkit/schematics 11.2.12
@angular/cli 11.2.12
@schematics/angular 11.2.12
@schematics/update 0.1102.12
ng-packagr 11.2.4
rxjs 6.6.7
typescript 4.1.5 |
@PowerKiKi You are correct, I was not able to reproduce this with latest Angular either. Closing this issue, thanks! |
@PowerKiKi I (respectfully) disagree. Please see the attachment, I have the same versions you posted. I'm not authorized to show you the code but I can ensure you QueryList is only used as a type for ContentChildren. This issue is not resolved. There might be other variables involved, but it's not resolved. |
@rojasjandro89 if you are able to share a minimum reproduction I can look into it. Before doing that though, is this also an issue when building the library using Ivy enabled? We're on the brink of supporting Ivy-compiled libraries using partial compilation (shipping in v12, planned for this week) so I'd be interesting to know if Ivy has the same issue. |
@JoostK thanks for the quick reply. I enabled Ivy and the warning disappeared. As for the minimum reproduction I'll try to create a stackblitz and I'll post it here but yeah... Ivy (once again) to the rescue 😅 |
Use `type` imports introduced in TypeScript 3.8, fix warnings for imports `OnInit`, `AfterViewInit`, `OnDestroy`, `ModuleWithProviders`... More details available on [False Positive: 'QueryList' is imported from external module '@angular/core' but never used #710](ng-packagr/ng-packagr#710 (comment))
This issue has been automatically locked due to inactivity. |
Type of Issue
Description
A warning is logged during build time if a component uses '@ContentChildren' or '@ViewChildren' annotation with QueryList type.
How To Reproduce
Create a new component, which has this property:
Expected Behaviour
No Warning should be logged, since QueryList is being used for type safety here.
Version Information
The text was updated successfully, but these errors were encountered: