angular icon indicating copy to clipboard operation
angular copied to clipboard

Report unused standalone imports

Open Lonli-Lokli opened this issue 2 years ago • 20 comments

Which @angular/* package(s) are relevant/related to the feature request?

common

Description

With the popularity of standalone components (pipes/directives), powered by Angular as well, there is a possibility that some components will be unused in templates while still imported by parent component, and so will increase bundle

Proposed solution

Report during the build that some.pipe/directive is imported but not used. It can be controlled via angulqrCompilerOptions of tsconfig

Alternatives considered

Nothing

Lonli-Lokli avatar Jul 09 '22 15:07 Lonli-Lokli

It is in the works :-)

pkozlowski-opensource avatar Jul 09 '22 15:07 pkozlowski-opensource

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

angular-robot[bot] avatar Sep 28 '22 14:09 angular-robot[bot]

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

angular-robot[bot] avatar Oct 17 '22 14:10 angular-robot[bot]

@pkozlowski-opensource Is this still in the works, or should we take @angular-robot's comment to mean that this won't be done?

MaximSagan avatar Nov 11 '22 06:11 MaximSagan

@MaximSagan I've removed the angular-robot comment - this is something we would love to address.

pkozlowski-opensource avatar Nov 11 '22 06:11 pkozlowski-opensource

@pkozlowski-opensource do you know the statistics of issues which pass votes? Seems like 20 votes is too much...

Lonli-Lokli avatar Nov 11 '22 08:11 Lonli-Lokli

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

angular-robot[bot] avatar Nov 11 '22 14:11 angular-robot[bot]

Seems like script for bot wasn't tested enough;)

Lonli-Lokli avatar Nov 11 '22 14:11 Lonli-Lokli

Seems like script for bot wasn't tested enough;)

@pkozlowski-opensource

MaximSagan avatar Nov 11 '22 22:11 MaximSagan

Will this also be possible for NgModules?

DaSchTour avatar Nov 22 '22 12:11 DaSchTour

Any news about this cool feature ? :)

mpontreau avatar Mar 10 '23 14:03 mpontreau

I want to reopen the pollling! I wasn't using Stand-Alone components until now and now I really want to have an auto-cleanup of unused components. :)

crowmagnumb avatar Jun 28 '23 18:06 crowmagnumb

This seems like it should be a pretty major thing now, especially with more and more people moving to standalone components?

So easy to end up with left-over imports hanging around that aren't needed anymore - especially if/when code gets copy-pasted from one component to another - and no easy way to auto-detect these, unless there is some other way I don't know about?

It's also quite difficult to do manually - especially if you have a lot of components, and especially since the imports and the templates that use them are usually in different files.

DanKing123 avatar Jul 11 '23 17:07 DanKing123

This seems like it should be a pretty major thing now, especially with more and more people moving to standalone components?

So easy to end up with left-over imports hanging around that aren't needed anymore - especially if/when code gets copy-pasted from one component to another - and no easy way to auto-detect these, unless there is some other way I don't know about?

It's also quite difficult to do manually - especially if you have a lot of components, and especially since the imports and the templates that use them are usually in different files.

This problem is not new to standalone; NgModules have always had those same challenges.

JoostK avatar Jul 11 '23 18:07 JoostK

This seems like it should be a pretty major thing now, especially with more and more people moving to standalone components? So easy to end up with left-over imports hanging around that aren't needed anymore - especially if/when code gets copy-pasted from one component to another - and no easy way to auto-detect these, unless there is some other way I don't know about? It's also quite difficult to do manually - especially if you have a lot of components, and especially since the imports and the templates that use them are usually in different files.

This problem is not new to standalone; NgModules have always had those same challenges.

Yes but this one is more easily solvable it seems. Also not an excuse. :)

crowmagnumb avatar Jul 11 '23 21:07 crowmagnumb

Yes, I would also like to mention that this is getting more important because of standalone components being used by more people. Here in my company, as we like to don't have imports that we do actually not need we have an additional code review step to check if the components imported by a component are actually used. That takes some time and I guess in terms of dev experience it would be great to instantly know if an import is used or not. This becomes important especially in projects where there is some continues refactoring going on. We had that for example when we migrated components to use the standalone paradigm and by that we also tried to refactor some parts, that ended up in some imports not needed anymore and it was some effort to find these imports...

So to sum up, I would also vote for this issue from the current point of view.

styriandev avatar Sep 12 '23 08:09 styriandev

standalone is default in Angular v17 now, so this warning would be convenient

xinthose avatar Dec 15 '23 21:12 xinthose

Are there any updates?

jahusa02 avatar Feb 15 '24 07:02 jahusa02

4/13/2024

eglove avatar Apr 14 '24 02:04 eglove

Definitively a MUST HAVE these days with Angular 17+ Come on!

n0futur3 avatar May 06 '24 13:05 n0futur3

@pkozlowski-opensource Any news about this?

s0h311 avatar May 21 '24 11:05 s0h311

Any updates on this?

kelvinsleonardo avatar May 30 '24 00:05 kelvinsleonardo

This issue is annoying, because it possibly increases the compile time and bundle size. But the other side of this issue, where an import is missing, as reported in #46351, is much more critical, because it can lead to runtime "missing behavior" without any errors or warnings, neither at build time or at runtime.

PowerKiKi avatar Jun 13 '24 05:06 PowerKiKi

I think this is an important feature for projects. It does not necessarily need to be in simple compilation (to maintain performance) => This could be an option or an specific command.

clem4net avatar Jun 24 '24 13:06 clem4net

Upvote

t-mish avatar Jul 24 '24 11:07 t-mish