parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.38k stars 2.27k forks source link

Have to clear cache and restart parcel on each almost each save #9729

Open a-rasin opened 3 months ago

a-rasin commented 3 months ago

🐛 bug report

Changes aren't getting picked up after the first save. I need to constantly clear the cache and rerun parcel. Other team members can run it fine (only hmr doesn't work for them) but for me the page in the browser doesn't change. Even with reloading and hard reloading notihng changes. I can see parcel doing some work building something but changes are not reflected in the browser unless I clear the cache and rerun parcel. This sounds extremely similar to #5660 but saving a file with echo changes nothing so the cause seems slightly different

🎛 Configuration (.babelrc, package.json, cli command)

NODE_ENV=development parcel --port 9000

🤔 Expected Behavior

Rebuild on every save and at least by refreshing the browser I get the latest code.

😯 Current Behavior

After one or two saves the page in the browser remains the same literally nothing changes. Parcel is building something in the terminal but it is not reflected in the browser even if I refresh.

🔦 Context

Been experiencing this issue probably for a year now it used to stop picking up changes after about 4 edits per file but now it reduced to 1 and it's driving me nuts my productivity is destroyed

💻 Code Sample

Sorry can't share the code

🌍 Your Environment

Software Version(s)
Parcel 2.11.0 tried with some earlier versions and also v2.8.2
Node 22.2.0 but tried with older versions possibly 20.x.x
npm/Yarn 1.22.22
Operating System arch linux, 6.8.9 tried with older versions as well
a-rasin commented 3 months ago

Also I think at some point parcel seems to stops doing any building on the terminal as well.

I am willing to try and work on this or at least debug it further using the source code. Any pointers for where to look or any potential causes would be very helpful.

mischnic commented 3 months ago

There are three stages where it could break:

  1. The file watcher should pick up all changes That happens here https://github.com/parcel-bundler/parcel/blob/c3505e59a96c3c95aea16954883afe059b8e6da8/packages/core/core/src/Parcel.js#L435
  2. Parcel should detect that the change should cause transformers to rerun and bundles to be rebuilt respondToFSEvents is responsible for determining what has to be recomputed: https://github.com/parcel-bundler/parcel/blob/c3505e59a96c3c95aea16954883afe059b8e6da8/packages/core/core/src/RequestTracker.js#L844 (Then, for example @parcel/transformer-js and @parcel/packager-js should rerun).
  3. In the browser, HMR should handle the update from the dev server and either update in place or reload. The updates are received here: https://github.com/parcel-bundler/parcel/blob/c3505e59a96c3c95aea16954883afe059b8e6da8/packages/runtimes/hmr/src/loaders/hmr-runtime.js#L135

For more logging inside Parcel (in the functions I referenced above), you can add console.log statements to e.g. node_modules/@parcel/core/lib/Parcel.js and node_modules/@parcel/transformer-js/lib/JSTransformer.js. Run it as yarn parcel build ... | cat to prevent log message from being cleared after builds.

benasher44 commented 3 months ago

Would it be possible to do a release that adds logging behind a flag (verbose or an env flag)? I can yarn patch it, but it might be more helpful to have logs that contain the information you would need/want for a more detailed bug report.

a-rasin commented 3 months ago

Ok, so something I noticed. I'm trying out emacs this is my second day using it and I noticed that parcel works with it. Previously I was using neovim. I'm guessing the way that neovim saves files doesn't trigger a rebuild at least not in the correct manner.

puresick commented 3 months ago

@a-rasin Try setting the following in your neovim configuration:

set backupcopy=yes

That changes how neovim saves a file (basically creating a copy and replacing the whole file with the above configuration).