Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Weird behavior with Rollup running twice on save #188

Open
arxpoetica opened this issue Dec 27, 2019 · 14 comments
Open

Weird behavior with Rollup running twice on save #188

arxpoetica opened this issue Dec 27, 2019 · 14 comments

Comments

@arxpoetica
Copy link
Member

It's unclear where this behavior is stemming from (might be Rollup, might be Sapper, might be Svelte, might be something weird on my computer), but I'm just going to put it here until we can isolate a little better.

Problem: when saving files, Rollup/restart runs twice; it's inconsistent with different ways of saving/updating files.

To repeat the behavior, do the following:

  1. install and run
npx degit "sveltejs/sapper-template#rollup" my-app
cd my-app
npm install
npm run dev
  1. save a file to see behavior

Open up a second terminal window and try the following:

cd my-app
echo " " >> src/routes/_layout.svelte

It's double saving/rolling up:

image

ODDLY if I open up the file and make a tweak in VIM, it does not double save/run. Can't figure out the difference.

@arxpoetica
Copy link
Member Author

Additional info: Node v13.5.0, npm 6.13.4, Mac OS Catalina 10.15.1

@silentworks
Copy link
Contributor

I have the same issue with the default Sapper rollup template. I am on macOS Mojave 10.14.5, Node 12.11.0/NPM 6.11.3.

@arxpoetica
Copy link
Member Author

arxpoetica commented Dec 28, 2019

@lukeed suggested using Chokidar:

i had this long time ago & when it pops up i just slap on chokidar

https://rollupjs.org/guide/en/#watch-options

Applying Chokidar DID make the problem go away, but...

I'm hesitant to close this ticket since the fix shouldn't necessarily be "just use Chokidar." It'd be nice to have a more permanent resolution to the problem.

@arxpoetica
Copy link
Member Author

One more note, @silentworks said the problem seemed to be related to Node 12+

@njbotkin
Copy link

Fairly certain this isn't Rollup's fault. I've been having the same problem (I just thought it was supposed to do that, heh). I get double builds on Windows 10, Node 12.x, whether chokidar is enabled or not. I get single builds on Windows 10, Node 10.x, whether chokidar is enabled or not. On Node 12.x, a minimal rollup config only builds once where the sapper config builds twice.

@njbotkin
Copy link

Okay, discovered a couple things.

For starters, the issue I was running into (and seems to be slightly different from @arxpoetica's issue) is Sapper is not actually building twice, it's just printing the "rebuilding..." message twice. Pretty superficial, not related to file watching.

As far as I can tell (again, for me), the difference between 10.x and 12.x stems from a subtle change in how process.nextTick() works. Changing nextTick in https://github.com/sveltejs/sapper/blob/master/src/api/dev.ts#L401 to use setTimeout fixes the issue. I'm not well-versed enough in Node.js lore to understand why the difference matters in this case.

I think @arxpoetica might be running into a combination of the process.nextTick thing and something else.

@arxpoetica
Copy link
Member Author

@njbotkin it does appear to be two issues, yes

@rob-balfre
Copy link

Getting the same issue. In my case it causes the browser to refresh 2 or 3 times which is super annoying and slowing me down. I've tried debugging with running sapper locally but got a bit lost in node hell!

src/components/Settings/Settings.svelte changed. rebuilding...
✔ service worker (69ms)
✔ server (1.6s)
✔ client (1.6s)
✔ service worker (1.1s)
✔ service worker (23ms)
✔ service worker (5ms)

@rob-balfre
Copy link

rob-balfre commented Jan 17, 2020

Downgrading from node v13 to v10 (using nvm) is my current workaround. Using setTimeout instead of nextTick didn't work for me, neither did using Chokidar. 🤷‍♂️

@trentjones21
Copy link

Downgrading to node v10 (nvm install v10.18.1) fixed it for me as well

@ISNIT0
Copy link

ISNIT0 commented May 12, 2020

Colleague and I had this, nvm install v10.18.1 worked a treat. Later versions of 10 didn't seem to help

@RemiKalbe
Copy link

Same issue with node v14.4, on macOS 10.15.5.

@mwilliams1188
Copy link

Anyone find a solution here without downgrading node?

@ronnidc
Copy link

ronnidc commented Jan 9, 2021

Same issue with node v12.19.1, sapper 0.27.0, Svelte 3.0.0, Rollup 1.20.0 running on macOS Big Sur 11.1

✔ server (870ms)
✔ client (886ms)
> Listening on http://localhost:3000
✔ service worker (13ms)

src/routes/_layout.svelte changed. rebuilding...

src/routes/_layout.svelte changed. rebuilding...
✔ server (196ms)
✔ client (275ms)
✔ service worker (8ms)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants