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

Process will exit when watch mode is on #730

Closed
susiwen8 opened this issue Jan 31, 2021 · 8 comments
Closed

Process will exit when watch mode is on #730

susiwen8 opened this issue Jan 31, 2021 · 8 comments

Comments

@susiwen8
Copy link
Contributor

Hi, amazing work on watch mode, but I have encounter under watch mode, after first build, process will exit, which I think it shouldn't happen.

Here is the script I use

build({
    // stdio: 'inherit',
    entryPoints: [path.resolve(__dirname, '../src/echarts.all.ts')],
    outfile: outFilePath,
    format: 'cjs',
    sourcemap: true,
    bundle: true,
    watch: {
       onRebuild(error, result) {
            if (error) {
                console.error('watch build failed:', error)
            } else {
                console.error('watch build succeeded:', result)
            }
        },
    }
})

pretty much the same code with doc.

I try to debug myself, found out this line would cause this issue. So what I propose as follow

      if (result.rebuild) {
        let old = result.rebuild.dispose;
        result.rebuild.dispose = () => {
          old();
          service.stop();
        };
      }
      else if (!options.watch) {
        service.stop();
      }

However I don't have faith on this, so would you confirm it? If I were right, I could make a PR for it.

@fernandopasik
Copy link

I have detected the same problem.

node .esbuild.cjs
watch build failed: Error: The service was stopped
    at Socket.afterClose (/myproject/node_modules/esbuild/lib/main.js:526:18)
    at Socket.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

@fernandopasik
Copy link

I tried your proposal @susiwen8 and I got an error on rebuild

watch build failed: Error: Build failed with 4 errors:
../../node_modules/esbuild/lib/main.js:550:33: error: [JavaScript plugins] callback is not a function
../../node_modules/esbuild/lib/main.js:550:33: error: [JavaScript plugins] callback is not a function
../../node_modules/esbuild/lib/main.js:550:33: error: [JavaScript plugins] callback is not a function
../../node_modules/esbuild/lib/main.js:550:33: error: [JavaScript plugins] callback is not a function
    at failureErrorWithLog (myproject/node_modules/esbuild/lib/main.js:1076:15)
    at myproject/node_modules/esbuild/lib/main.js:892:46
    at myproject/node_modules/esbuild/lib/main.js:576:15
    at Generator.next (<anonymous>)
    at myproject/node_modules/esbuild/lib/main.js:28:61
    at new Promise (<anonymous>)
    at __async (myproject/node_modules/esbuild/lib/main.js:10:10)
    at handleRequest (myproject/node_modules/esbuild/lib/main.js:545:40)
    at handleIncomingPacket (myproject/node_modules/esbuild/lib/main.js:602:7)
    at Socket.readFromStdout (myproject/node_modules/esbuild/lib/main.js:506:7) {

@evanw
Copy link
Owner

evanw commented Jan 31, 2021

Thanks for the report. Clearly I was rushing when I got this out last night. Using the startService API should be a good workaround for now.

Instead of doing this:

esbuild.build({...})

Do this for now:

esbuild.startService().then(service => service.build({...}))

I'll get this fixed today. Thanks again for the report, and sorry about the trouble.

@fernandopasik
Copy link

Thank you @evanw for taking this one quickly and for all the hard work!

@camsloanftc
Copy link

Hey @evanw, It looks like this is still an issue when attempting to use esbuild.serve. It immediately throws if I add watch.onRebuild to the buildConfig object.

I am on 0.8.44 and can confirm it has no issues with just using the build command directly.

Would you like me to open a new issue for this?

@evanw
Copy link
Owner

evanw commented Feb 12, 2021

Is the error message Cannot use "watch" with "serve"? It is an intentional limitation that you can't use both watch and serve at the same time. They are both two different ways of doing incremental builds.

@camsloanftc
Copy link

Ah yes sorry - you're right. Is there a similar callback to onRebuild using serve? The use case being to run an action anytime the files have changed.

@evanw
Copy link
Owner

evanw commented Feb 13, 2021

The local server doesn't monitor for file changes at all. It only rebuilds when new HTTP requests come in. If you want to detect file changes too I suppose you could run esbuild twice, once for the local web server and once for the file watcher.

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