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

🐛 BUG: wrangler dev does not watch for source changes when using a custom build command #631

Closed
jahands opened this issue Mar 17, 2022 · 8 comments · Fixed by #646 or #562
Closed

Comments

@jahands
Copy link
Contributor

jahands commented Mar 17, 2022

What version of Wrangler are you using?

0.0.19

What operating system are you using?

MacOS

Describe the Bug

Running wrangler dev with a custom build command doesn't watch files for changes and rebuild/reload like Miniflare does.

Steps to reproduce:
Clone this repo: https://github.com/jahands/wrangler-dev-example

  1. git clone git@github.com:jahands/wrangler-dev-example.git
  2. cd wrangler-dev-example
  3. npm install
  4. npx wrangler dev --local
  5. Change something in index.ts and save it - it doesn't rebuild
  6. npx miniflare --live-reload
  7. Change something in index.ts and save it - it rebuilds and reloads the script

The wranger.toml uses some deprecated fields, but I also included a second wrangler.toml named wrangler-non-deprecated-example.toml which has no deprecated fields, and it still doesn't work.
(version with deprecated fields used here because miniflare doesn't work with the non-deprecated version.)

@jahands jahands added the bug label Mar 17, 2022
@petebacondarwin
Copy link
Contributor

Thanks for this @jahands. The problem is that while Wrangler can trigger the custom build, it does not know what the inputs to that build are, so it doesn't know when to restart the build.

I think this will come down to good migration documentation rather than a fix on the Wrangler side of things.

For simple cases, where the custom build was literally just bundling the code (as in your excellent reproduction) the new Wrangler 2 builtin bundling will do that for you and watch and rerun as necessary, so a custom build step is not needed.

For more complex cases, such as in a Pages Remix project, one should set up the build as a separate process that does its own watching of its input files, and then wrangler dev will just watch the output and rebuild as needed.

@jahands
Copy link
Contributor Author

jahands commented Mar 17, 2022

Ah fair enough - if I do something custom I should expect to need my own watcher/autobuilder.

+1 for a doc for people moving from this configuration + miniflare - it wasn't clear why standalone miniflare watched files when using a custom build and wrangler dev didn't.

@threepointone
Copy link
Contributor

Setting build.watch_dir should make this work

How does miniflare know which folder to watch?

@petebacondarwin
Copy link
Contributor

Ah I forgot about watch_dir. This would resolve most watching problems if but not if there are potentially opaque dependencies that only the custom build knows about.

@threepointone
Copy link
Contributor

I'm still curious to know how miniflare does it, we should totally steal that.

@petebacondarwin
Copy link
Contributor

Isn't Miniflare just runnin esbuild under the hood?

@mrbbot
Copy link
Contributor

mrbbot commented Mar 18, 2022

From the wrangler.toml configuration docs:

watch_dir optional

The directory to watch for changes while using wrangler dev, defaults to the src relative to the project root directory.

...so Miniflare implicitly watches the src directory (if watch_dir isn't set) and rebuilds if anything changes in there.

@threepointone
Copy link
Contributor

TIL! Damn we should check what else we've missed.

@threepointone threepointone moved this to Must-have in workers-sdk Mar 18, 2022
@threepointone threepointone added this to the 2.0 milestone Mar 18, 2022
threepointone added a commit that referenced this issue Mar 19, 2022
Via wrangler 1, when using custom builds in `wrangler dev`, `watch_dir` should default to `src` of the "project directory" (i.e - wherever the `wrangler.toml` is defined if it exists, else in the cwd.

Fixes #631
threepointone added a commit that referenced this issue Mar 19, 2022
Via wrangler 1, when using custom builds in `wrangler dev`, `watch_dir` should default to `src` of the "project directory" (i.e - wherever the `wrangler.toml` is defined if it exists, else in the cwd.

Fixes #631
threepointone added a commit that referenced this issue Mar 20, 2022
Via wrangler 1, when using custom builds in `wrangler dev`, `watch_dir` should default to `src` of the "project directory" (i.e - wherever the `wrangler.toml` is defined if it exists, else in the cwd.

Fixes #631
Repository owner moved this from Must-have to Done in workers-sdk Mar 20, 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
4 participants