Closed yoannmoinet closed 4 months ago
It seems to be the same problem in rspack too: https://github.com/unjs/unplugin/blob/1d7e13f06a605ced44b671acc2c25b7536b13c0e/src/rspack/index.ts#L106-L110
Tried my hand on a PR too: https://github.com/unjs/unplugin/pull/390
Environment
Node 18.19.0 Unplugin 1.10.1 Yarn 1.22.19
Reproduction
Having a plugin with an async
writeBundle
hook.Describe the bug
It results in the plugin executing outside of webpack's "build process".
I noticed it while writing tests, and jest was constantly failing because it was trying to log outside of its process.
Additional context
I think I've confirmed it in the code:
https://github.com/unjs/unplugin/blob/1d7e13f06a605ced44b671acc2c25b7536b13c0e/src/webpack/index.ts#L218-L222
Should be:
Similarly to esbuild: https://github.com/unjs/unplugin/blob/1d7e13f06a605ced44b671acc2c25b7536b13c0e/src/esbuild/index.ts#L169-L170
I think the best fallback for now is to use
buildEnd
instead, but I'm not sure it is executed exactly at that moment for every bundlers 😞I was able to fix it on my side with a
yarn patch
which resolved the issue.Logs
No response