question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 https://github.com/webpack/webpack/blob/2151f56ae73b35722c56432c9b34820626d72e53/lib/NormalModule.js#L879

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
7rulnikcommented, May 12, 2021

@alexander-akait the only reason why I decided to create an issue, not a question in discussions, because that implementation based on Tobias’s own comment. Also, it works in webpack 4 and I didn’t find anything related to this change in changelog. So this is why I raised this issue.

So basically I want to modify a source of modules. I added repro into main post https://github.com/7rulnik/webpack-repro-13361

I also understand that this can be worked around by adding a dependency to parser.hooks, for example, ConstDependency.

0reactions
michenlycommented, Nov 8, 2021

For anyone who ran into similar problem and wondering how parser.hooks can be use to modify module. The trick is accessing module using parser.state.module inside a parser.hooks.program.tap(...)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compilation Hooks | webpack
The Compilation module is used by the Compiler to create new compilations (or builds). ... SyncBailHook. Fired at the beginning of dependency optimization....
Read more >
Webpack plugin: how can I modify and re-parse a module ...
How I got it working: hook into compilation 's 'seal' plugin, iterate through the compilation's module s and find the one you want ......
Read more >
Workflows — Spack 0.11 documentation
Some module systems put a prefix on the names of modules created by Spack. ... reset tic tput $ spack view --verbose --dependencies...
Read more >
Dependency Management in Go - GitLab Docs
Go packages must be stored in a version control repository on a VCS server. Dependencies are fetched directly from their VCS server or...
Read more >
https://unpkg.com/webpack/types.d.ts
This can be set to 'false' to omit emitting e. g. for SSR. ... Module, Module>; /** * Modules in value are building...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found