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. |
northernCold
added a commit
to northernCold/unplugin-tailwindcss-shortener
that referenced
this issue
May 2, 2024
unplugin bug[#293](unjs/unplugin#293)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to 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: