Skip to content

Broken import of esm modules #19547

@mariusGundersen

Description

@mariusGundersen

Bug report

PR #19434 broke how chunks are loaded when they have a directory segment in the output.filename. The tests in the PR don't sufficiently test that the output is correct. This breaks esm imports in webpack 5.99.6 and above. This problem was correctly identified in #19495 but dismissed, claiming that the /./ in the final path is not an issue.

What is the current behavior?

The concatenated url is incorrect. It includes both the publicPath, which is absolute to the server, and the relative path based on the current chunk file. The combination is nonsensical unless the current chunk is placed in the root directory.

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

The issue is reproducible in this simple test case: https://github.com/mariusGundersen/webpack-module-publicPath-issue.

What is the expected behavior?

The path to the chunk should not depend on the current chunk location, since it uses the publicPath, which makes the lookup incorrect. The rootOutputDir should only be used when publicPath is auto.

Other relevant information:
webpack version: 5.99.8
Node.js version: 22.6.0
Operating System: Windows and Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions