Skip to content

watchpack watch not triggering when symlinked node_module files are modified when using webpack 'symlinks: true' #61

Closed

Description

@txinfo

In a regular webpack project, a symlinked module in node_modules is watched for changes correctly (as long as the module in question is referenced).

However, if using 'symlinks:true' in webpack to resolve symlinks to their full path (e.g. when using --preserve-symlinks behaviour in angular-cli), it does not seem to watch for changes anymore.

I have tracked this behaviour down to the 'followSymlinks' option of DirectoryWatcher in watchpack (https://github.com/webpack/watchpack/blob/master/lib/DirectoryWatcher.js). The followSymlinks option is always set to false which causes an issue with file watching when webpack is set to resolve symlinks. If it is manually set to true in this scenario, the watching works. Ideally this option would be configurable.

Activity

  1. jukibom commented on Jan 19, 2018

    @jukibom

    Yep, I'm seeing this exact problem with an angular 5 app and a linked node library I'm working on. Manually setting the flag works correctly.

  2. jukibom commented on Jul 11, 2018

    @jukibom

    anyone looking for a horrifying stopgap waiting for this to be fixed, add
    "postinstall": "sed -i 's/followSymlinks: false/followSymlinks: true/g' node_modules/watchpack/lib/DirectoryWatcher.js"
    to package.json. Probably don't commit it into your repo though ;P

  3. svilendobrev commented on Aug 29, 2018

    @svilendobrev

    same finding here, with same fix, for the same problem in opposite setup... bunch of symlinked files (under webpack + resolve.symlink=false) are not noticed for being changed.. because the actual links do not change. the followSymlinks:true fixes that.

  4. liujingbreak commented on Nov 2, 2018

    @liujingbreak

    Me, another Angular 7 developer facing same problem.
    It has been 10 months...

  5. SomeoneIsWorking commented on Nov 22, 2018

    @SomeoneIsWorking

    Experiencing this with 'symlinks: false'

  6. LaKing commented on Dec 9, 2018

    @LaKing

    Finally I found this. Fix from @jukibom works!

  7. floribon commented on Dec 12, 2018

    @floribon

    I'm also having this problem when I symlink a folder in my node_modules and use symlinks: false.

    @jukibom workaround works for now. Thanks!

  8. bkniffler commented on Jun 2, 2019

    @bkniffler

    Just in case @jukibom command doesn't work on your platform, you can install replace package from npm globally or locally and add this in postinstall.

    replace 'followSymlinks: false' 'followSymlinks: true' node_modules/watchpack/lib/DirectoryWatcher.js

    Its 100% analog to @jukibom solution, so all credits to him!

  9. raf64flo commented on Jun 12, 2019

    @raf64flo

    I fear @jukibom's workaround is not working anymore since commit 805b665 which removes dependency to chokidar and symlinks configuration..

    @sokra any chance to have a symlink option with the new native watcher, before v2.0.0 goes GA?

  10. cristian-spiescu commented on Jan 19, 2020

    @cristian-spiescu
    1. Even if this issue is closed by @sokra following the merge of a pull request that seems to fix the issue, the issue still exists. I.e. in webpack, there is still no way to pass the followSymlinks option.
    2. @raf64flo, in my case @jukibom's fix still works. At time of writing I use webpack 4.41.0.
    3. I built upon @jukibom's suggestion in order to perform the modification at runtime, via monkeypatching, and have a "less temporary" temporary code:
    var Module = require('module');
    var originalRequire = Module.prototype.require;
    
    Module.prototype.require = function () {
      const original = originalRequire.apply(this, arguments);
      if ("chokidar" === arguments[0]) {
        var originalWatch = original.watch;
        original.watch = function () {
          const options = arguments[1];
          if (options) {
            options.followSymlinks = true;
          }
    
          return originalWatch.apply(this, arguments);
        }
      }
      return original;
    };

    This piece of code should execute early, in the start script which ultimately launches webpack. In my case, I use https://github.com/gsoft-inc/craco, so I put it in craco.config.js which is getting called quite early.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions