Skip to content

Double write when writeToDisk is true #2270

@AdrianBannister

Description

@AdrianBannister

Bug Description

When writeToDisk is set to true Webpack will emit to the default outputFileSystem (normally not memfs due to this logic), and then when the assetEmitted hook fires webpack-dev-middleware also writes the file to the same location (Compiler code, dev middlerware code).

I know there might be some case where someone provides a custom outputFileSystem, but for the common case this seems like a waste, no? I picked this up while debugging storybook.

Link to Minimal Reproduction and step to reproduce

https://github.com/AdrianBannister/webpack-dev-middleware-bug-report

Steps:

  1. npm install
  2. node test.js
  3. See two console.log messages for the same file being written twice

Expected Behavior

Not to write twice when writeToDisk: true

Actual Behavior

Writing twice to disk for the same file and content.

Environment

System:
    OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (8) x64 Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
    Memory: 47.58 GB / 61.80 GB
  Binaries:
    Node: 24.12.0
    Yarn: 1.22.22
    npm: 11.6.2

Is this a regression?

No

Last Working Version

No response

Additional Context

I guess you could say this was "broken" in this PR #1537

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions