Skip to content

export in library works only for last entry module #15936

Closed

Description

@vankop

Bug report

export in library works only for last entry module

What is the current behavior?

in webpack config like:

module.exports = {
  entry: ["a", "b", "c"],
  output: {
    library: { type: "global" }
  }
};

only exports from c will be used

If the current behavior is a bug, please provide the steps to reproduce.

https://github.com/TGRHavoc/webpack-mvp

What is the expected behavior?
should use all exports

Other relevant information:
webpack version: latest
Node.js version:
Operating System:
Additional tools:

Activity

  1. webpack-bot commented on Sep 16, 2022

    @webpack-bot
    Contributor

    This issue had no activity for at least three months.

    It's subject to automatic issue closing if there is no activity in the next 15 days.

  2. added
    status: staleNo author response after a needs: request; close candidate
    on Sep 16, 2022
  3. alexander-akait commented on Sep 16, 2022

    @alexander-akait
    Member

    bump

  4. removed
    status: staleNo author response after a needs: request; close candidate
    on Sep 16, 2022
  5. alan-agius4 commented on Sep 19, 2022

    @alan-agius4

    Is there any workaround for this? Other than creating a barrel?

  6. alexander-akait commented on Sep 19, 2022

    @alexander-akait
    Member

    @alan-agius4 currently, no workaround (only multi compiler builds), but feel free to fix send a PR with fix

  7. TGRHavoc commented on Dec 6, 2022

    @TGRHavoc

    @alan-agius4 currently, no workaround (only multi compiler builds), but feel free to fix send a PR with fix

    Does anyone know where one would get started at debugging/fixing this issue?

  8. Judahmeek commented on Jan 29, 2024

    @Judahmeek

    @TGRHavoc I'd start by checking what the default for the output.library.name configuration is.

    A client of mine used some custom output.library.name logic back in the day to support multiple library sub-modules.

  9. moved this to Priority - High in webpack 5/6on Feb 15, 2024
  10. added
    status: staleNo author response after a needs: request; close candidate
    on Apr 29, 2024
  11. 9 remaining items

  12. added a commit that references this issue on Mar 28, 2026
    eb214cd
  13. whoami-amrit commented on Apr 11, 2026

    @whoami-amrit

    I was trying to replicate this issue and noticed as per the documentation, we are multi-part entries are used in this case - https://github.com/webpack/webpack/tree/main/examples/multi-part-library

    So this seems like a intentional design choice. Don't you think?

    Workarounds

    1. Barrel file
    2. Add the following to index.html
            <script src="dist/index.js"></script>
            <script src="dist/scriptB.js"></script>
            <script src="dist/scriptC.js"></script>
    

    @TGRHavoc

  14. TGRHavoc commented on Apr 11, 2026

    @TGRHavoc

    I was trying to replicate this issue and noticed as per the documentation, we are multi-part entries are used in this case - https://github.com/webpack/webpack/tree/main/examples/multi-part-library

    So this seems like a intentional design choice. Don't you think?

    Workarounds

    1. Barrel file
    2. Add the following to index.html
            <script src="dist/index.js"></script>
            <script src="dist/scriptB.js"></script>
            <script src="dist/scriptC.js"></script>
    

    @TGRHavoc

    Sorry, my memory is a little fuzzy on this issue (I'm trying to use the discussion thread to re-jog my memory https://github.com/orgs/webpack/discussions/15929).
    I think the issue was around exposing the exported functions to the HTML from multiple files. As far as I could find out, exporting everything to a global library should have done exactly this but it wouldn't.
    Because I was trying to modernise a very large legacy system, adding additional scripts to every page wasn't feasible and neither was barrel files. In the end, I didn't touch the older stuff and only modernised newer functionality because of this friction with webpack (I originally decided to use webpack because I thought it had this functionality and would allow me to move forward whilst keeping the system functioning).

    Basically, if webpack exposed all exported functions for a named global library, I would expect it to also expose all exported functions for a non-named library. The fact that only the last entry gets exposed does feel like a bug and not intented (maybe it should be all or none?)

  15. added theissue type on Aug 9, 2026
  16. webdevelopersrinu commented on Aug 10, 2026

    @webdevelopersrinu

    Hi I'd like to work on this issue.

    I've traced the root cause: in AbstractLibraryPlugin.js, finishEntryModule is only called on the last entry dependency (deps[deps.length - 1]), so exports from earlier entries in the array are never flagged as used and get dropped from the library output.

    My plan is to call finishEntryModule for all entry dependencies and adjust the startup runtime so the library exposes the merged exports of all entry modules, plus add test cases under test/configCases/library. Please let me know if this direction sounds right — happy to adjust based on feedback.

  17. webdevelopersrinu commented on Aug 10, 2026

    @webdevelopersrinu

    I've implemented the approach described in my earlier comment — fix in the library plugin layer, test case included, zero regressions in the library test suite. The PR (#21662) was auto-closed by the quality bot, which appears to be flagging my contributor history rather than the change itself (CLA signed, changeset included). Would a maintainer be willing to take a look and reopen if the approach looks right?

  18. LeonxLJX commented on Sep 2, 2026

    @LeonxLJX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedMaintainers welcome a community PR for thiswebpack-5Concerns the webpack 5 line

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions