[Bug] Infinite loop on the webpack 5 example
kbariotis opened this issue · comments
- I'd be willing to submit the fix
Describe the bug
When running the webpack 5 example, there is an endless loop with webpack compiling the same files again and again.
To Reproduce
Just run the webpack 5 example.
Environment if relevant (please complete the following information):
- OS: OSX Big Sur
- Node version 14
- Mochapack version NA
- Webpack version 5
I found a gross workaround. You can compare webpack's filesystem with the incoming changes you want to write to your module, and bail out if they're the same:
const modulePath = "<YOUR MODULE'S *ABSOLUTE* PATH>"
const moduleContents = "<YOUR MODULE'S CONTENTS>"
let finalInputFileSystem = compiler.inputFileSystem;
while (finalInputFileSystem && finalInputFileSystem._inputFileSystem) {
finalInputFileSystem = finalInputFileSystem._inputFileSystem;
}
const existing = finalInputFileSystem._virtualFiles[modulePath];
if (existing.contents != moduleContents) {
virtualModules.writeModule(modulePath, moduleContents);
}
So maybe the fix here would just be that webpack-virtual-modules
needs to ignore calls to writeModule
when they wouldn't change the module.
@stevenpetryk This comparison should be done on caller side. wrtieModule
is expected to match the behaviour of fs.writeFile
, e.g. when you write the same contents the file timestamp should be updated and recompilation should be scheduled. It is a bug in the example
Closing as works as intended, we also have #89 which tells about the opposite intended behaviour. And only one behaviour from these two can exists, because they are in direct contradiction to each another.
It is a bug in the example
I assume the said bug is still there? Running the webpack 5 example, I see an infinite compilation loop.
It is a bug in the example
I assume the said bug is still there? Running the webpack 5 example, I see an infinite compilation loop.
Yes, it is still present in the example.
This still appears to be an issue. Seems to happen with @shopify/web-worker/webpack
which uses webpack-virtual-modules. Happens when using webpack-dev-server
(webpack serve
) or webpack --watch
.
We are using this API on our end, and are seeing this infinite loop issue still. Opening a PR for a potential fix, but open to other suggestions. I don't think this and #89 need to be conflicting, we could hopefully have both issues fixed.