GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Unused assets left by code optimization · Issue #20209 · webpack/webpack

Unused assets left by code optimization #20209

New issue
Copy link
New issue
Copy link
Closed
#20723
Closed
Unused assets left by code optimization#20209
#20723
Copy link
Assignees
hai-x

Description

@MattIPv4
MattIPv4
opened on Dec 7, 2025
Issue body actions

Bug Description

When using code optimization to drop unused code, assets that were emitted but no longer referenced are still emitted.

Link to Minimal Reproduction and step to reproduce

https://github.com/MattIPv4/webpack-asset-repro

  • npm ci
  • npm run build
  • ls dist/*.png
  • for each file.png, cat dist/main.js | grep <file.png>

One png should be referenced in dist/main.js, while the other won't be as it was used by dead code.

Expected Behavior

Assets that are emitted but later made unused by code optimization should be removed from the emitted assets

Actual Behavior

Assets are always emitted even if all references to them are dropped by code optimization

Environment

System:
    OS: macOS 26.1
    CPU: (14) arm64 Apple M4 Pro
    Memory: 97.52 MB / 24.00 GB
  Binaries:
    Node: 22.13.1 - /Users/mattcowley/.local/state/fnm_multishells/85154_1765079840717/bin/node
    npm: 10.9.2 - /Users/mattcowley/.local/state/fnm_multishells/85154_1765079840717/bin/npm
    pnpm: 10.20.0 - /Users/mattcowley/.local/state/fnm_multishells/85154_1765079840717/bin/pnpm
  Browsers:
    Chrome: 142.0.7444.177
    Firefox Developer Edition: 146.0
    Safari: 26.1
    Safari Technology Preview: 26.0
  Packages:
    webpack-cli: ^6.0.1 => 6.0.1

Is this a regression?

None

Last Working Version

No response

Additional Context

No response

Activity

  1. xiaoxiaojx commented on Dec 9, 2025

    @xiaoxiaojx
    xiaoxiaojx
    on Dec 9, 2025
    Member
    More actions

    You need to add the following line to your package.json file. See more: optimization.sideEffects

    + "sideEffects": false
  2. MattIPv4 commented on Dec 9, 2025

    @MattIPv4
    MattIPv4
    on Dec 9, 2025
    Author
    More actions

    That worked! ...but I don't understand why? If the import of the image were to be seen as a side effect, why isn't the import itself left in place? All that gets left is a completely unreferenced image asset?

  3. MattIPv4 commented on Dec 9, 2025

    @MattIPv4
    MattIPv4
    on Dec 9, 2025
    Author
    More actions

    Hm... in the real world it doesn't seem to work though... alveusgg/extension#401 if I pnpm build here, ls build/static/media/ambassadors/*/emote*.png still returns files generated even though they're unused.

  4. hai-x
    self-assigned this
    on Jan 23, 2026
  5. hai-x commented on Jan 24, 2026

    @hai-x
    hai-x
    on Jan 24, 2026
    Member
    More actions

    Hm... in the real world it doesn't seem to work though... alveusgg/extension#401 if I pnpm build here, ls build/static/media/ambassadors/*/emote*.png still returns files generated even though they're unused.

    https://github.com/alveusgg/data/blob/9370cf4b0d88b69fc917b0aea1054e5eca678a2c/src/ambassadors/images.ts#L846

    It looks like you’re unioning all assets into a single map. Since their actual usage is determined at runtime, we can't safely remove them. We can only analyze them statically to remove unused assets.

  6. hai-x commented on Jan 24, 2026

    @hai-x
    hai-x
    on Jan 24, 2026
    Member
    More actions

    That worked! ...but I don't understand why? If the import of the image were to be seen as a side effect, why isn't the import itself left in place? All that gets left is a completely unreferenced image asset?

    We can think import the image as side effect effect, so the unused image asset won't exist in the bundle and import statement will be removed too.

  7. MattIPv4 commented on Jan 24, 2026

    @MattIPv4
    MattIPv4
    on Jan 24, 2026
    Author
    More actions

    I'm not sure I follow though, their usage isn't determined at runtime, their usage is dropped from the bundle, the assets just remain in the bundle unreferenced?

  8. hai-x commented on Jan 25, 2026

    @hai-x
    hai-x
    on Jan 25, 2026
    Member
    More actions

    their usage isn't determined at runtime

    Sorry for the confusion. What I meant is that, for alveusgg/data@9370cf4/src/ambassadors/images.ts#L846, the usages of those import bindings of the asset modules cannot be determined at compile-time right now.

    Because in optimization.innerGraph (a.k.a. deep scope analysis), we don’t track ObjectPattern (your case: ambassadorEmoteImages and ambassadorBadgeImages mapping to many images) to form the entire usage chain (export -> import). But, I think we can improve it.

    their usage is dropped from the bundle

    This is actually done by Terser (default minimizer), not webpack itself. You can verify webpack’s raw bundle via optimization.minimize: false.

  9. MattIPv4 commented on Jan 25, 2026

    @MattIPv4
    MattIPv4
    on Jan 25, 2026
    Author
    More actions

    Ah okay. Does Webpack not give Terser the ability to drop assets when it drops their imports? This still feels like a Webpack issue as Terser is the default minimizer that I haven't configured at all?

  10. hai-x commented on Jan 25, 2026

    @hai-x
    hai-x
    on Jan 25, 2026
    Member
    More actions

    Does Webpack not give Terser the ability to drop assets when it drops their imports?

    Yeah. Terser only applies to JavaScript, not to image assets.

    This still feels like a Webpack issue as Terser is the default minimizer that I haven't configured at all?

    You are right. When you enable optimization.minimize: true (it's enabled by default in production mode), webpack will use it as default minimizer.

  11. alexander-akait commented on Feb 15, 2026

    @alexander-akait
    alexander-akait
    on Feb 15, 2026
    Member
    More actions

    @hai-x is this issue resolved?

  12. MattIPv4 commented on Feb 15, 2026

    @MattIPv4
    MattIPv4
    on Feb 15, 2026
    Author
    More actions

    Because in optimization.innerGraph (a.k.a. deep scope analysis), we don’t track ObjectPattern (your case: ambassadorEmoteImages and ambassadorBadgeImages mapping to many images) to form the entire usage chain (export -> import). But, I think we can improve it.

    I took this to be an indication that something can be done on Webpack's side to solve for this so that this situation doesn't leave dangling assets?

  13. hai-x commented on Feb 18, 2026

    @hai-x
    hai-x
    on Feb 18, 2026
    Member
    More actions

    @alexander-akait

    @hai-x is this issue resolved?

    One thing worth noting is that the issue of the initial repro has already been resolved in #20352 and it has been released.

    However, regarding:

    Hm... in the real world it doesn't seem to work though... alveusgg/extension#401 if I pnpm build here, ls build/static/media/ambassadors//emote.png still returns files generated even though they're unused.

    there’s still additional work needed.

    @MattIPv4

    I took this to be an indication that something can be done on Webpack's side to solve for this so that this situation doesn't leave dangling assets?

    Yeah, we are still working on it - #20467. But the tests shows that we will introduce some regressions, so we need more time to explore it.

    Reacted by Alexander Akait and Matt Cowley
  14. alexander-akait commented on Feb 21, 2026

    @alexander-akait
    alexander-akait
    on Feb 21, 2026
    Member
    More actions

    @shoryax this issue already assigned

  15. ayaan-mirza7 commented on Feb 27, 2026

    @ayaan-mirza7
    ayaan-mirza7
    on Feb 27, 2026
    More actions

    Hi I would like to work on these issue .can you assign it to me

  16. alexander-akait commented on Mar 21, 2026

    @alexander-akait
    alexander-akait
    on Mar 21, 2026
    Member
    More actions

    @Bhupendra-Pratap You will be banned in future for copying AI generated output, do not violate our rules

  17. alexander-akait
    closed this as completedin #20723on Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @hai-x
    hai-x

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.