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

Since 0.12.17, --watch fail silently when running under lerna #1885

Closed
compulim opened this issue Dec 24, 2021 · 3 comments
Closed

Since 0.12.17, --watch fail silently when running under lerna #1885

compulim opened this issue Dec 24, 2021 · 3 comments

Comments

@compulim
Copy link

compulim commented Dec 24, 2021

Versions
First repro 0.12.17
Also repro latest, 0.13, 0.12
Not repro 0.12.16, 0.12.0, 0.11
OS Ubuntu and Windows
Node/npm 14.17.6/6.14.15 and 16.13.1/8.1.2

When using lerna run <scriptname> --stream to run esbuild --watch with >= 0.12.17, it quit silently. I am using lerna@4.0.0 (latest), it was released about 10 months ago, which is earlier than 0.12.17.

0.12.16

image

In the screenshot above, the root package of the monorepo will run esbuild@0.12.16 --watch. ESBuild will say "build finished, watching for changes".

0.12.17

image

In the screenshot above, I updated to esbuild@0.12.17. When running it through lerna, ESBuild fail silently and quit immediately. There are no output files produced.

However, when running without --watch (via npm run build), it works without issues, regardless of whether lerna's --parallel and --stream flag is set or not.

image

Repro

I have prepared a bare minimal repo, https://github.com/compulim/experiment-lerna-esbuild. Please use GitHub Codespaces to try it out on the cloud.

After clone

  • Run npm install at root to prepare the repository
  • npm start
    • It should start esbuild --version && esbuild src/index.js --bundle --outfile=lib/index.js --watch

ESBuild is located under packages/app. To change version of esbuild:

  • cd packages/app
  • npm install esbuild@0.12.6

By default, GitHub Codespaces use Node 14. You can use nvm to change its version.

Workaround

When running esbuild, use concurrently to wrap around it. concurrently will not close stdin on start.

In the bare minimal repo, modify packages/app/package.json:

-    "start": "esbuild --version && esbuild src/index.js --bundle --outfile=lib/index.js --watch"
+    "start": "npx concurrently \"esbuild --version && esbuild src/index.js --bundle --outfile=lib/index.js --watch\""

image

@evanw
Copy link
Owner

evanw commented Dec 24, 2021

Watch mode in esbuild is terminated when stdin is closed. Closing stdin indicates to esbuild that you want to end watch mode.

One way to fix this is to change Lerna itself. The ignore here could be changed to inherit instead: https://github.com/lerna/lerna/blob/a47fc294393a3e9507a8207a5a2f07648a524722/core/child-process/index.js#L65.

Another way to fix this is to avoid closing stdin:

diff --git a/packages/app/package.json b/packages/app/package.json
index 5424c2b..2ac3235 100644
--- a/packages/app/package.json
+++ b/packages/app/package.json
@@ -6,7 +6,7 @@
   "main": "lib/index.js",
   "scripts": {
     "build": "esbuild --version && esbuild src/index.js --bundle --outfile=lib/index.js",
-    "start": "esbuild --version && esbuild src/index.js --bundle --outfile=lib/index.js --watch"
+    "start": "esbuild --version && sleep 9999999999 | esbuild src/index.js --bundle --outfile=lib/index.js --watch"
   },
   "author": "",
   "license": "MIT",

@kzc
Copy link
Contributor

kzc commented Dec 24, 2021

Duplicate of #1511

luwes added a commit to luwes/elements that referenced this issue Jan 10, 2022
luwes added a commit to luwes/elements that referenced this issue Jan 10, 2022
cjpillsbury pushed a commit to muxinc/elements that referenced this issue Jan 10, 2022
@luwes
Copy link

luwes commented Jan 11, 2022

In case you need a cross-platform solution check out ours above, it uses JS setInterval to keep the stdin open until manually stopped.

Changing the stdio in Lerna has some other difficulties seems, comments here:
lerna/lerna#608 (review)

@evanw evanw closed this as completed in 77194c8 Sep 1, 2022
luwes added a commit to luwes/elements that referenced this issue Sep 7, 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
Development

No branches or pull requests

4 participants