-
Notifications
You must be signed in to change notification settings - Fork 116
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
buildStart hook is not async in webpack #293
Comments
It does not seem to be asynchronous, for webpack I tried to solve it without success |
The workaround right now is to add webpack specific code to await the promise. const plugin = createUnplugin(() => {
return {
name: "my-plugin",
webpack(compiler) {
compiler.hooks.beforeRun.tapPromise("my-plugin", async () => {
// await Promise in here
});
}
}}) |
yes,At present, this can only be done first. |
unplugin bug[#293](unjs/unplugin#293)
some investigationsthe Lines 183 to 203 in 1b697de
this issue will not appear in Rspack, because currently Rspack's make hook is Unfortunately, there is no thisArg of buildStart is await plugin.buildStart.call(context) // contextOptionsFromCompilation
IMO, to comment that buildStart in webpack only supports sync is a good solution, and let users who wants to use async use workaround #293 (comment) |
Environment
unplugin 1.3.1
webpack 5.76.2
Node.js v16.14.2
Reproduction
buildStart
perform async operation.transform
hook rely on ordered completionbuildStart
and its result.StackBlitz: https://stackblitz.com/edit/webpack-webpack-js-org-1qvdhq?file=package.json&view=editor (
pnpm start
to run webpack programmatically,pnpm test
to run tests which will also do the build programatically).Describe the bug
buildStart
is not an async hook, and invokingawait
will immediately continue the build pipeline, which will have unexpected consequences.Vitest:
Node.js:
Additional context
buildStart
is async and can be used to perform initial initialisation fortransform
hook invocations.transform
hook seems to be correctly async, which means you can await forbuildStart
fulfillment in it, which involves moving async logic ofbuildStart
to a separate function and then also creating another plugin variable in which you will store promise returned by that separate async function call. But it's not obvious and still feels like a mistake/oversight.Logs
The text was updated successfully, but these errors were encountered: