Skip to content

Module dependencies set in buildModule hook are getting reset during the build  #13361

@7rulnik

Description

@7rulnik

Bug report

What is the current behavior?

I'm trying to modify the source of the module based on this comment

So my code looks like this:

compilation.hooks.buildModule.tap('MyPlugin', (module) => {
	module.addDependency(new MyDependency())
})

But it's doesn't work because in the build method webpack resets dependencies of module

this.clearDependenciesAndBlocks();

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

Clone https://github.com/7rulnik/webpack-repro-13361 and run yarn && yarn webpack

What is the expected behavior?

I don't quite follow the logic of clearDependenciesAndBlocks, but I thing that it should contain check for dependencies.length

Other relevant information:
webpack version: 5.36.2
Node.js version: v14.15.4
Operating System: MacOS 11.3 M1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions