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

buildEnd not trigger with vite 5.0.10 #15418

Open
7 tasks done
MaxRenglet opened this issue Dec 23, 2023 · 10 comments
Open
7 tasks done

buildEnd not trigger with vite 5.0.10 #15418

MaxRenglet opened this issue Dec 23, 2023 · 10 comments
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) rollup plugin compat

Comments

@MaxRenglet
Copy link

Describe the bug

Hi,

It seems that buildEnd hook is not trigger anymore in vite 5.0.10 with a custom plugin. I run npm run dev then ctl-c to exit the process and buildEnd isn't trigger.

I tried with vite 4.5.1 and it works.

For the reproduction, I created a small plugin to test it on stackblitz ! It should console.log buildStart then buildEnd when the process is exited.

Thanks for the great work btw !

Reproduction

https://stackblitz.com/edit/vitejs-vite-8cekfx?file=vite.config.js

Steps to reproduce

npm install && npm run dev

System Info

System:
    OS: macOS 14.2.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 120.44 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.volta/tools/image/node/20.10.0/bin/node
    npm: 10.2.3 - ~/.volta/tools/image/node/20.10.0/bin/npm
  Browsers:
    Safari: 17.2.1
  npmPackages:
    vite: ^5.0.10 => 5.0.10

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Dec 23, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@userquin
Copy link
Contributor

userquin commented Dec 23, 2023

why apply: 'serve'? It shouldn't be called, if Vite 4 calling buildEnd it should be a bug (no makes sense having buildEnd in a dev plugin).

@MaxRenglet
Copy link
Author

Hi @userquin, yeah that what i thought, buildEnd is trigger in build mode but shouldn't be trigger in dev mode.. but it does in Vite 4.5.1.

Do you know if there is a similar hook working in dev ?

@userquin
Copy link
Contributor

No, but you can try adding build hooks (https://rollupjs.org/plugin-development/ and https://vitejs.dev/guide/api-plugin#transformindexhtml)... (apply can be also a function)

@MaxRenglet
Copy link
Author

Thanks @userquin, I will figure this out.

Should I rename the issue about the buildEnd triggered in dev in Vite 4.5.1 ?

@bluwy
Copy link
Member

bluwy commented Dec 26, 2023

buildEnd should be called in dev too, it's documented in https://vitejs.dev/guide/api-plugin.html#universal-hooks. Seems like a bug it's not being called now.

@bluwy bluwy added pending triage rollup plugin compat p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Dec 26, 2023
@bluwy
Copy link
Member

bluwy commented Dec 26, 2023

I took a look, and it seemed to work in Vite 4 because we took control of Ctrl+C via setRawMode, which was part of the breaking change related to the CLI shortcuts. Any versions other than v4 didn't work, as if you're relying on this behaviour, it's similar to listening to the Node.js process-exit-hook, and it's known to not always be reliable.

We're currently using SIGTERM to listen for process exit, but that only works in controlled environments such as child processes. I tested, and only SIGINT seems to reliably get triggered, but it was removed in a04db16.

SIGINT is generally very tricky to work with unfortunately. You need to call process.exit() manually if you add a handler. But if you have multiple handlers (maybe some framework adds theirs too), then calling process.exit() will halt the subsequent added handlers.

This SO answer has some more details. If we do something similar, it might also help lessen the impact of #9470

@userquin
Copy link
Contributor

userquin commented Dec 26, 2023

@bluwy the plugin shouldn't be called in build, it has apply: 'serve', check Conditional Application

EDIT: I think I have misunderstood the issue

@bluwy
Copy link
Member

bluwy commented Dec 26, 2023

I don't see the plugin running when running npm run build in the repro 🤔

@MaxRenglet
Copy link
Author

Hi, @bluwy thanks for the heads up and explaination !

I will wait to see if a fix is push to migrate to Vite 5 !

Thanks ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) rollup plugin compat
Projects
None yet
Development

No branches or pull requests

3 participants