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.

[Bug] virtual module trigger extra compilation in webpack 5

See original GitHub issue
  • I’d be willing to submit the fix

Describe the bug

Using the latest webpack 5 and the latest webpack-virtual-modules. I notice that webpack is logging out 2 compilation in watch mode.

To Reproduce

Run webpack --watch to reproduce using this brranch: https://github.com/michenly/webpack-5-demo/tree/webpack-virtual-modules-error

Minimally, use webpack-virtual-modules (I did this in both in a plugin with .apply and in webpack config’s plugin directly with the same result)

new VirtualModulesPlugin({'test.js': `export default 'test123'`})

Log out compilation message by tapping into compiler.hooks.compile and see two compilation message as soon as webpack --watch is run

Screenshots

Screen Shot 2021-08-11 at 3 22 05 PM

Environment if relevant (please complete the following information):

  • OS: OSX 11.15.1
  • Node version: v12.14.0
  • Mochapack version: ?
  • Webpack version: 5.50.0
  • webpack-virtual-modules version: 0.4.3

Additional context

I also log out complier.removedFiles in compiler.hooks.watchRun, notice how the virtual module is listed as files that was removed.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
andy0130twcommented, Dec 23, 2021

@larixer Sure. I have opened a PR.

2reactions
andy0130twcommented, Dec 23, 2021

Update: I have worked out a more robust, Proxy-based solution that treats the original WatchFileSystem as an abstract object. Should be more resilient to breaking changes in Webpack and Watchpack.

Code: https://github.com/andy0130tw/webpack-virtual-modules/blob/24d823f3133da9f397224cdfedd39be341546b21/src/wfs.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 release (2020-10-10)
Webpack 5 adds additional external types to cover more applications: promise : An expression that evaluates to a Promise. The external module is ......
Read more >
Compiler Hooks | webpack
The Compiler module is the main engine that creates a compilation instance with all the options passed through the CLI or Node API....
Read more >
Loader Interface - webpack
A loader is a JavaScript module that exports a function. The loader runner calls this function and passes the result of the previous...
Read more >
Output - webpack
Compiling to System.register format allows you to System.import('/bundle.js') without additional configuration and has your webpack bundle loaded into the ...
Read more >
Compilation Hooks | webpack
A compilation instance has access to all modules and their dependencies (most of which are circular references). It is the literal compilation of...
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