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

esbuild --watch can't run in background when started from shell script #1511

Closed
sehugg opened this issue Aug 9, 2021 · 3 comments
Closed

Comments

@sehugg
Copy link

sehugg commented Aug 9, 2021

It looks as if you run esbuild --watch as a background process in a shell script (with "&") it exits immediately. Probably related to issue #1449, as it didn't do this in 0.12.16. Example:

#!/bin/sh
./node_modules/.bin/esbuild src/main.ts --outfile=/tmp/bundle.js --watch &
sleep 3
cat /tmp/bundle.js # no file created

To prevent this, it would probably be best to hide the exit-on-stdin-close behavior behind a --watch-stdin option. I don't see any other bundlers with a more elegant solution.

@kzc
Copy link
Contributor

kzc commented Aug 9, 2021

try:

sleep 99999 | esbuild main.ts --outfile=out.mjs --watch &

or

sleep 99999 | nohup esbuild main.ts --outfile=out.mjs --watch &

@brianmhunt
Copy link

brianmhunt commented Feb 7, 2022

tl;dr Redirect pipe </dev/zero

Perhaps the clearest and most versatile option here is this:

make esbuild-watch </dev/null &
# or in the above example
./node_modules/.bin/esbuild src/main.ts --outfile=/tmp/bundle.js --watch  </dev/zero &

(thanks @ctcarton)

This fills the Stdin pipe with 512 bytes of zeros so it doesn't auto-close.

setsid

Another option is setsid e.g.

In our case we use a Makefile so it looks like this:

setsid make esbuild-watch &

This is Linux-specific i.e. it won't work on Mac or Windows.

true |

An alternative option might be:

true | make esbuild-watch &
  • [ ]

@Reemh
Copy link

Reemh commented Jun 30, 2022

I've had a similar problem when I was trying to run that as a preLaunchTask for a VS Code extension. However, in my case the fix was to set a correct "problemWatcher" to be "$esbuild-watch" in .vscode/tasks.json file.
Perhaps this could help someone else struggling with the same problem.

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

No branches or pull requests

4 participants