Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite rebuild loop in vagrant environment in watch mode #12340

Closed
thecreazy opened this issue Jan 5, 2021 · 11 comments · Fixed by webpack-contrib/sass-loader#927
Closed

Comments

@thecreazy
Copy link

Bug 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

@alexander-akait
Copy link
Member

Please provide all steps to reproduce, because I can't reproduce

@thecreazy
Copy link
Author

Please provide all steps to reproduce, because I can't reproduce

Hi @alexander-akait, what tipe of information could be utils for you ? can I pass you all the plugins and loader that I use ?

provide all steps to reproduce

I don't know hot to provide all the steps, is just an issue related with the state of our environment and code :/

@alexander-akait
Copy link
Member

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

webpack doesn't remove directories, so something external does this

Hi @alexander-akait, what tipe of information could be utils for you ? can I pass you all the plugins and loader that I use ?

Yes, as minimal - configuration, as maximum reproducible test repo

I don't know hot to provide all the steps, is just an issue related with the state of our environment and code :/

What is command you use to run webpack and setup vagrant environment

@thecreazy
Copy link
Author

thecreazy commented Jan 5, 2021

webpack doesn't remove directories, so something external does this

in fact I think that the issue is related to that, nobody delete the folder/file, in fact I can navigate inside the modules folder on the vagrant machine and also on my Mac, but the compiler.removedFiles return this path inside the WatchRunPlugin write by me (the implementation is on the question)

Yes, as minimal - configuration, as maximum reproducible test repo

thx, just some time and I prepare all

@alexander-akait
Copy link
Member

@thecreazy feel free to ping me when it was ready

@thecreazy
Copy link
Author

@alexander-akait sorry for the delay but I was looking for a way to give you a better solution

I create a bug example repo https://github.com/thecreazy/webpack-bug-example-repo

in this example, (look the readme), the rebuild is done just two time but the bug is the same, in the deletedFiles we found two files that are not deleted by nobody

in our real repo the files are a lot and the rebuild process is done more time but the issue is the same

let me know if I can help you more

thx

@sokra
Copy link
Member

sokra commented Jan 7, 2021

Note that all entries in deletedFiles should be absolute paths, so something is putting relative paths into fileDependencies (e. g. via this.addDependency in loaders). I tracked this down to sass-loader: result.stats.includedFiles includes a few relative paths next to a lot absolute paths. This is only happening for .json files and globs imported by sass. There are processed by node-sass-json-importer resp. node-sass-glob-importer. Not sure if these plugins need to do something to provide correct paths to result.stats.includedFiles or if sass-loader need to do something here. To me it looks like that these relative paths are kind of virtual sass modules created by these importer plugins and they should be ignored here. On the other hand the JSON file should be watch and contribute the cache invalidation, so it must be added via addDependency but is not listed as absolute path.

@sokra
Copy link
Member

sokra commented Jan 7, 2021

importers probably would need to ability to provide their own includedFiles as result.

@thecreazy
Copy link
Author

so do you think is a bug relative to this plugins ? because with Webpack 4 all works good, maybe are not compatible with 5

@sokra
Copy link
Member

sokra commented Jan 7, 2021

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).

@alexander-akait
Copy link
Member

@thecreazy here bug in node-sass too, node-sass runs importer before built-in sass resolving and returns relative path for the prev argument for the next importer, fixed in sass (dart-sass), so my recommendation - migrate from node-sass on sass (dart-sass, also you can see node-sass is deprecated). Now we output good warnings, unfortunately nothing to fix on webpack side more, also I prepare patch for mode-sass feel free to feedback webpack-contrib/sass-loader#927

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants