Infinite rebuild loop in vagrant environment in watch mode
See original GitHub issueBug report
What is the current behavior? Using Webpack 5.11.1 (update from 4) inside a vagrant machine on macOS i have a loop of rebuild in watch mode, for example:
- starting the client:watch with
npx webpack --devtool eval-source-map --config webpack.client.js --watch
- first build works
- start a lot of rebuild because inside the
compiler.removedFiles
variables found the/src/common/js/modules
path that is not really deleted from fs
If the current behavior is a bug, please provide the steps to reproduce.
this is our configuration:
{
mode: 'development',
target: 'web',
watchOptions: { poll: 500, ignored: [ 'public', 'build' ] },
watch: true,
devtool: false,
entry: {
'bundle.0.0.1': [
'/var/www/hs-goldenrod/wls/PROJECTNAME/src/js/client.js'
]
},
resolve: {
extensions: [ '.js', '.jsx', '.scss', '.css' ],
alias: {
'module-analytics': '/var/www/PROJECTNAME/src/packages/module-analytics',
...
},
fallback: {
fs: false,
net: false,
tls: false,
console: false,
child_process: false,
path: '/node_modules/path-browserify/index.js',
crypto: '/node_modules/crypto-browserify/index.js',
stream: '/node_modules/stream-browserify/index.js',
https: '/node_modules/https-browserify/index.js',
http: '/node_modules/stream-http/index.js',
zlib: '/node_modules/browserify-zlib/lib/index.js'
}
},
output: {
path: 'public/js',
publicPath: '/js/',
filename: '[name].min.js',
chunkFilename: '[name].0.0.1.min.js'
},
node: {},
optimization: { splitChunks: { cacheGroups: [Object] }, minimize: true }
the deleted and changed file list is printed by an our Webpack plugin
class WatchRunPlugin {
// Define `apply` as its prototype method which is supplied with compiler as its argument
apply(compiler) {
// Specify the event hook to attach to
compiler.hooks.watchRun.tap("WatchRunPlugin", (comp) => {
if (comp.modifiedFiles) {
const changedFiles = Array.from(
comp.modifiedFiles,
(file) => `\n ${file}`
).join("");
console.log("\n===============================");
console.log("FILES CHANGED:", changedFiles);
console.log("===============================");
}
if (comp.removedFiles) {
const removedFiles = Array.from(
comp.removedFiles,
(file) => `\n ${file}`
).join("");
console.log("\n===============================");
console.log("FILES REMOVED:", removedFiles);
console.log("===============================");
}
});
}
}
module.exports = () => {
return new WatchRunPlugin();
};
and this is a example prompt
[webpack-cli] watching files for updates...
3% setup watch run webpack-cli[webpack-cli] Compilation starting...
3% setup watch run WatchRunPlugin
===============================
FILES CHANGED:
/var/www/hs-goldenrod/wls/PROJECTNAME/src/common/js/server.js
===============================
===============================
FILES REMOVED:
===============================
99% done plugins webpack-cli[webpack-cli] Compilation finished
asset server.bundle.js 24.9 MiB [emitted] (name: server)
asset PropertyOverlay.bundle.js 100 KiB [emitted] (name: PropertyOverlay)
asset DetailsOverlay.bundle.js 96.9 KiB [emitted] (name: DetailsOverlay)
asset AmenitiesFilter.bundle.js 46.1 KiB [emitted] (name: AmenitiesFilter)
asset ReviewsOverlay.bundle.js 32.5 KiB [emitted] (name: ReviewsOverlay)
orphan modules 3.07 MiB [orphan] 542 modules
runtime modules 4.07 KiB 12 modules
javascript modules 7.36 MiB
modules by path ./node_modules/ 3.69 MiB 623 modules
modules by path ./src/ 3.66 MiB
modules by path ./src/packages/ 2.89 MiB 171 modules
modules by path ./src/common/js/ 789 KiB
cacheable modules 788 KiB 2 modules
2 modules
json modules 495 KiB
modules by path ./node_modules/har-schema/lib/*.json 6.93 KiB 18 modules
modules by path ./node_modules/iconv-lite/encodings/tables/*.json 86.7 KiB 8 modules
modules by path ./node_modules/encoding/node_modules/iconv-lite/encodings/tables/*.json 86.7 KiB 8 modules
modules by path ./node_modules/ajv/lib/refs/*.json 5.58 KiB 3 modules
webpack 5.11.1 compiled with 1 warning in 21320 ms
[webpack-cli] watching files for updates...
3% setup watch run webpack-cli[webpack-cli] Compilation starting...
3% setup watch run WatchRunPlugin
===============================
FILES CHANGED:
===============================
===============================
FILES REMOVED:
/var/www/hs-goldenrod/wls/PROJECTNAME/src/common/js/modules
===============================
99% done plugins webpack-cli[webpack-cli] Compilation finished
asset server.bundle.js 24.9 MiB [emitted] (name: server)
asset PropertyOverlay.bundle.js 100 KiB [emitted] (name: PropertyOverlay)
asset DetailsOverlay.bundle.js 96.9 KiB [emitted] (name: DetailsOverlay)
asset AmenitiesFilter.bundle.js 46.1 KiB [emitted] (name: AmenitiesFilter)
asset ReviewsOverlay.bundle.js 32.5 KiB [emitted] (name: ReviewsOverlay)
orphan modules 3.07 MiB [orphan] 542 modules
runtime modules 4.07 KiB 12 modules
javascript modules 7.36 MiB
modules by path ./node_modules/ 3.69 MiB 623 modules
modules by path ./src/ 3.66 MiB
modules by path ./src/packages/ 2.89 MiB 171 modules
modules by path ./src/common/js/ 789 KiB
cacheable modules 788 KiB 2 modules
2 modules
json modules 495 KiB
modules by path ./node_modules/har-schema/lib/*.json 6.93 KiB 18 modules
modules by path ./node_modules/iconv-lite/encodings/tables/*.json 86.7 KiB 8 modules
modules by path ./node_modules/encoding/node_modules/iconv-lite/encodings/tables/*.json 86.7 KiB 8 modules
modules by path ./node_modules/ajv/lib/refs/*.json 5.58 KiB 3 modules
webpack 5.11.1 compiled with 1 warning in 18108 ms
In the first case the rebuild is correct because the edit of the /var/www/hs-goldenrod/wls/PROJECTNAME/src/common/js/server.js
file was made by me
but in the second case the rebuild is wrong because nobody delete the folder /var/www/hs-goldenrod/wls/PROJECTNAME/src/common/js/modules
and in the fs the folder is present and not touched
In fact the wrong rebuild
is not just one but go in a infinite loop that have always the /var/www/hs-goldenrod/wls/PROJECTNAME/src/common/js/modules
path inside the deletedFiles
What is the expected behavior?
just rebuild if a file is changed and not if a folder that is not deletes is in deleted list
Other relevant information: webpack version: 5.11.1 Node.js version: v12.13.1 Operating System: vagrant machine with Debian
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:11 (7 by maintainers)
There is a difference how webpack 4 and 5 handle watching of non-existing files. These invalid paths are treated as non-existing (since fs calls fail).
importers probably would need to ability to provide their own
includedFiles
as result.