Skip to content

Export of CJS require("file.json") has broken in 5.107.1 #21135

Description

@Knagis

Have you used AI?

None

Bug Description

export const data = require("./data.json");

in production build since 5.107.1 this exports empty object.

Link to Minimal Reproduction and step to reproduce

https://github.com/Knagis/webpack-json-req-issue

Expected Behavior

exported variable has the contents of the JSON file

Actual Behavior

empty object exported.

Environment

System:
    OS: Windows 11 10.0.26200
  Binaries:
    Node: 24.11.1
    Yarn: 1.22.22
  Packages:
    webpack: 5.107.2 => 5.107.2 
    webpack-cli: ^7.0.2 => 7.0.2

Is this a regression?

Yes (please specify version below)

Last Working Version

5.107.0

Additional Context

using the imported json data inside the module itself (even simple console.log(data)) mitigates the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions