Skip to content

Add option to enable/disable followSymlinks of watchpack #6845

Closed

Description

@immortal-tofu

Context:
You have project A in babel 6 and project B transpiled via babel 7. You run a webpack watch in package B directory to create bundle while you code.
If you npm link package B in package A, and run webpack in package A, it will throw an error because he doesn't find dependencies.
A webpack's issue is open here: #1866

Solution
In webpack, it's possible to disable symlinks via symlinks: false. It works and babel (of package A) won't try to transpile package B. Sadly, if you do this, webpack won't react to change.
It's possible to change this behavior with followSymlinks in watchpack/chokidar. A PR has been added there to add this option: webpack/watchpack#72

Now, we need the last part: add an exposed option in webpack configuration to enable/disable this watchpack new option. As stated by @TheLarkInn, it could be planned for webpack v5.

Activity

  1. added
    webpack-5
    on May 3, 2018
  2. added this to the webpack 5 milestone on May 3, 2018
  3. SEAPUNK commented on May 7, 2018

    @SEAPUNK

    Why is this planned for webpack 5? Can't this land in webpack 4 as a feature request? I don't see how any of this would be a breaking change, this is primarily a non-breaking feature (or even a bugfix, since watching is obviously broken).

  4. bcowell commented on May 25, 2018

    @bcowell

    Would also like to see this included in webpack 4 as it is a bug.

  5. Globegitter commented on Aug 11, 2018

    @Globegitter

    Agree with the sentiment here, this is either a backwards compatible feature or a bug-fix so there should be no issue shipping it with with v4 and it seems quite a few people would benefit from it.

  6. immortal-tofu commented on Oct 14, 2018

    @immortal-tofu
    Author

    Well, since PR on watchpack didn't land yet, we can't do a lot... Comments and upvote PR linked in inital post :(

  7. achrefhafedh commented on Mar 6, 2019

    @achrefhafedh

    AND FINALLY in Webpack 5

  8. Neira1991 commented on Mar 6, 2019

    @Neira1991

    greatttt!!!!

  9. wittibs commented on Apr 25, 2019

    @wittibs

    @birdy @evilebottnawi - I saw this issue was marked as "D0 first commit" so I decided to pursue it :P

    In researching this issue, I think I understand the problem, but I am unable to reproduce the issue with webpack not picking up on changes in symlinked module. I created a sample repo to demonstrate how I am unable to reproduce this issue. Is this still an issue? Or has it been fixed?

    Thanks!

  10. neonick commented on Sep 26, 2019

    @neonick

    @immortal-tofu it looks like something you can close

  11. immortal-tofu commented on Sep 26, 2019

    @immortal-tofu
    Author

    I close issue for now. I think it's ok now.

  12. 7 remaining items

  13. immortal-tofu commented on Feb 25, 2020

    @immortal-tofu
    Author

    I don't know if it's fixed in v5. I opened this issue 2 years ago and so far, I didn't see an answer "Problem solved see commit 35D43F53" ;)

  14. alexander-akait commented on Feb 25, 2020

    @alexander-akait
    Member
  15. slint commented on Feb 25, 2020

    @slint

    Solved for webpack@5, you can the option here https://github.com/webpack/watchpack#api

    That's on Watchpack (i.e. it now allows passing the flag). But what would an appropriate weback.config.js look like though to use the flag? I imagined something like this:

    module.exports = {
      //...
      watchOptions: {
        followSymlinks: true
      }
    };

    Or to allow full flexibility on what is passed to the Watchpack constructor:

    module.exports = {
      watchOptions: {
      //...
        watchpackConfig: {  // this probably overrides Webpack's default config options 
          followSymlinks: true,
          // ...
        }
      }
    };

    But none of these are reflected in the WebpackOptions schema currently.

  16. alexander-akait commented on Feb 25, 2020

    @alexander-akait
    Member

    Oh, yes, we need update schema, WIP

  17. barisusakli commented on Feb 25, 2020

    @barisusakli

    Thanks, I just modified the source and changed followSysmlinks to true for now.

  18. aviramaz commented on May 17, 2020

    @aviramaz

    It'll be solved as part of webpack v5?
    Someone has any recommendation how to implement nicely for webpack v4?

  19. slint commented on May 17, 2020

    @slint

    Not a particularly "nice" way, but since Webpack v5 is not yet released, a solution is to use the patch-package library to patch watchpack. Here's the patch diff, which also sets the depth parameter to 1 (needed for MacOS):

     
    diff --git a/node_modules/watchpack/lib/DirectoryWatcher.js b/node_modules/watchpack/lib/DirectoryWatcher.js
    index 940f616..210a1b7 100644
    --- a/node_modules/watchpack/lib/DirectoryWatcher.js
    +++ b/node_modules/watchpack/lib/DirectoryWatcher.js
    @@ -53,8 +53,8 @@ function DirectoryWatcher(directoryPath, options) {
     	this.watcher = chokidar.watch(directoryPath, {
     		ignoreInitial: true,
     		persistent: true,
    -		followSymlinks: false,
    -		depth: 0,
    +		followSymlinks: true,
    +		depth: 1,
     		atomic: false,
     		alwaysStat: true,
     		ignorePermissionErrors: true,
  20. WeijieZhu0204 commented on Oct 16, 2020

    @WeijieZhu0204

    @slint It works !

  21. alexander-akait commented on Oct 16, 2020

    @alexander-akait
    Member
  22. added
    help wanted
    on Oct 16, 2020
  23. nitinkatyal1314 commented on Jul 23, 2021

    @nitinkatyal1314

    Is this working with webpack 5? I have enabled followSymlinks but no luck. This is my devServer configuration

    devServer: { followSymlinks: true }

    I see that changes to dependent library component (linked via npm link) triggers recompilation but the changes are not reflected in the browser.

  24. alexander-akait commented on Jul 23, 2021

    @alexander-akait
    Member

    devServer doesn't have this option

  25. nitinkatyal1314 commented on Jul 27, 2021

    @nitinkatyal1314

    devServer doesn't have this option

    Are you sure about this? I am a little confused based on docs which actually point to watchOptions inside devServer conf. Also, when I put { followSymlinks: true } in webpack conf, nothing happens but adding it to devServer actually makes my app to recompile (though it does not hot reloads).

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

    help wantedwebpack-5

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions