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

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

Closed
txinfo opened this issue Jan 16, 2018 · 10 comments · Fixed by #114

Comments

@txinfo
Copy link

txinfo commented Jan 16, 2018

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.

@jukibom
Copy link

jukibom commented Jan 19, 2018

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.

@jukibom
Copy link

jukibom commented Jul 11, 2018

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

@svilendobrev
Copy link

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.

@liujingbreak
Copy link

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

@SomeoneIsWorking
Copy link

Experiencing this with 'symlinks: false'

@LaKing
Copy link

LaKing commented Dec 9, 2018

Finally I found this. Fix from @jukibom works!

@floribon
Copy link

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!

@bkniffler
Copy link

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!

@raf64flo
Copy link

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?

@cristian-spiescu
Copy link

cristian-spiescu commented Jan 19, 2020

  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.

cexbrayat pushed a commit to Ninja-Squad/data-discovery that referenced this issue Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants