Skip to content

Watch doesn't work correctly with links #12503

Closed

Description

@TomSssM

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Webpack file watcher ignores changes in symlinked files if resolve > symlinks options is set to false.

If the current behavior is a bug, please provide the steps to reproduce.

I have created a minimal reproducible repo to test the issue:

  • go to ./project
  • do npm ci
  • then start local server by running npm run server
  • start Webpack file watcher by running npm run watch
  • change the file in ./package/Logger (you could try changing the message getter for example, this way the changes are easy to see)

What is the expected behavior?

The changes made in Logger module should appear on the page (e.g. Logger should append a different message). Instead Webpack doesn't re-build the Logger module.

I found a similar issue here.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

Node.js version 12.19.0

Webpack version 5.10.3

Activity

  1. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    Can't reproduce, watch works as expected

  2. added
    webpack-5
    on Jan 25, 2021
  3. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    You need webpack-dev-server if you want to see changes on the page, please update webpack-cli to the latest version, install webpack-dev-server and use webpack serve command to run dev server, --watch only watch files (it can be useful for developers which develop library and other rare cases), it is not include client code for reloading and hot module replacement

  4. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    @alexander-akait watch doesn't re-build ../package/Logger.js is it really expected behavior? watch is supposed to re-build files if any is changed, does it include packages as well? If so, then it is a bug.

  5. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    It re-build files, look at console

  6. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    The changes made in Logger module should appear on the page (e.g. Logger should append a different message).

    No, changes will not be appeared, because nobody reload the page

  7. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    Changes works on each change on Logger.js:

    [webpack-cli] Compilation starting...
    (node:2506126) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
    BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
            Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
            Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
    [webpack-cli] Compilation finished
    asset runtime.3257a4a1eff8ce2ecff1.js 6.69 KiB [emitted] [immutable] (name: runtime)
    asset package.c441a94aec26a6bc73e0.js 1.5 KiB [emitted] [immutable] (name: package) (id hint: defaultVendors)
    asset main.0f930fc8ca28029879b1.js 1.49 KiB [emitted] [immutable] (name: main)
    asset index.html 357 bytes [emitted]
    Entrypoint main 9.68 KiB = runtime.3257a4a1eff8ce2ecff1.js 6.69 KiB package.c441a94aec26a6bc73e0.js 1.5 KiB main.0f930fc8ca28029879b1.js 1.49 KiB
    runtime modules 3.17 KiB 4 modules
    cacheable modules 591 bytes
      ./src/index.js 315 bytes [built] [code generated]
      ./node_modules/package/Logger.js 276 bytes [built] [code generated]
    webpack 5.10.3 compiled successfully in 91 ms
    [webpack-cli] watching files for updates...
    [webpack-cli] Compilation starting...
    [webpack-cli] Compilation finished
    assets by status 9.68 KiB [cached] 3 assets
    Entrypoint main 9.68 KiB = runtime.3257a4a1eff8ce2ecff1.js 6.69 KiB package.c441a94aec26a6bc73e0.js 1.5 KiB main.0f930fc8ca28029879b1.js 1.49 KiB
    cached modules 591 bytes (javascript) 3.17 KiB (runtime) [cached] 6 modules
    webpack 5.10.3 compiled successfully in 16 ms
    [webpack-cli] watching files for updates...
    [webpack-cli] Compilation starting...
    [webpack-cli] Compilation finished
    assets by status 9.68 KiB [cached] 3 assets
    Entrypoint main 9.68 KiB = runtime.3257a4a1eff8ce2ecff1.js 6.69 KiB package.c441a94aec26a6bc73e0.js 1.5 KiB main.0f930fc8ca28029879b1.js 1.49 KiB
    cached modules 591 bytes (javascript) 3.17 KiB (runtime) [cached] 6 modules
    webpack 5.10.3 compiled successfully in 11 ms
    [webpack-cli] watching files for updates...
    
  8. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    Changes are still missing after full page reload, bundle containing the code from package likewise doesn't update though Webpack writes logs

  9. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    Because you need dev server to reload page as I described above, webpack only bundle files and nothing to know when you need reload page, so you need webpack-dev-server and webpack to see changes on the page

  10. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    Oh, I see the problem

  11. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    The problem that I am experiencing is that the dist/package.[hash].js does not include changes made in watch mode, it is only possible if i change symlinks to true

  12. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    I wonder if it is a good idea to add something like followSymlinks to watchOptions so that the file watcher will resolve symlinks in watch mode

  13. 1 remaining item

  14. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    followSymlinks already in watchOptions

  15. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author
  16. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    Let's just say in the project I am working on it is necessary to disable symlinks =)

  17. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member
  18. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    I added it blindly to my config but everything got even worse:

    /Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:94
                                    throw e;
                                    ^
    
    Error: ENOENT: no such file or directory, readlink '/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/Users'
        at Object.readlinkSync (fs.js:1035:3)
        at LinkResolver.resolve (/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:47:27)
        at LinkResolver.resolve (/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:36:31)
        at LinkResolver.resolve (/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:36:31)
        at LinkResolver.resolve (/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:36:31)
        at LinkResolver.resolve (/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:36:31)
        at LinkResolver.resolve (/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:36:31)
        at LinkResolver.resolve (/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:36:31)
        at LinkResolver.resolve (/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:36:31)
        at LinkResolver.resolve (/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/node_modules/watchpack/lib/LinkResolver.js:36:31) {
      errno: -2,
      syscall: 'readlink',
      code: 'ENOENT',
      path: '/Users/ilyakortasov/Documents/sandbox/webpack-aliases/project/Users'
    }
    
  19. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    But you can't do it, you need resolve symlinks, because ./node_modules/package is link, even followSymlinks will not help, because you use import { Logger } from 'package/Logger'; and package/Logger is link, so resolving impossible

  20. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    You see we use Webpack aliases in our project, these aliases need to work not only in the project directory but also in the symlinked package directories. If we resolve symlinks, then Webpack aliases don't work inside symlinked packages and everything crashes. Is there any other workaround?

  21. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    You see we use Webpack aliases in our project

    I don't see, in package.json

    Webpack aliases don't work inside symlinked packages and everything crashes

    Please clarify, aliases work everywhere

    Is there any other workaround?

    No workarounds, you disable symlinks, but wait they will work 😕 Wrong

  22. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    The best way to explain is with code: go to the minimal reproducible repo and switch to aliases branch, then run npm run watch, Webpack will not be able to resolve generated because of symlinks: true option. If you set symlinks to false, then everything works.
    Note: I just updated my repo, make sure to pull it first

  23. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    Bug in cache, set cache: false, and all works fine

  24. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    Original issue - #12246
    PR - #12254

  25. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    Horray! Everything works now, thanks 🎉

  26. alexander-akait commented on Jan 25, 2021

    @alexander-akait
    Member

    Some things were a little unclear, I thought you were expecting an automatic reload and want fully disable symlinks, let's close because duplicate

  27. TomSssM commented on Jan 25, 2021

    @TomSssM
    Author

    Oh I see now why you thought this way, gotta be clearer next time =)

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

    webpack-5

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions