buildStart hook is not async in webpack
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 156
- PR merge metrics
- No merged PRs in 30d
Description
Environment
unplugin 1.3.1
webpack 5.76.2
Node.js v16.14.2
Reproduction
- Have
buildStartperform async operation. - Have
transformhook rely on ordered completionbuildStartand 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 invoking await will immediately continue the build pipeline, which will have unexpected consequences.
Vitest:
-- webpack call
-- webpack end
-- buildStart call ← buildStart waits 1 second to resolve a promise
-- transform call ← transform called before buildStart is fulfilled
× transform thrown Error: transform method was called either before buildStart call was completed or after it has thrown an error
-- transform end
√ buildStart return ← timer fires, buildStart fulfills
-- buildStart end
(Test timeout)
Node.js:
-- webpack call
-- webpack end
-- buildStart call
-- transform call
transform call without without buildStart completion, throwing!
× transform thrown Error: transform method was called either before buildStart call was completed or after it has thrown an error
-- transform end
UNHANDLED EXPECTION
Error: transform method was called either before buildStart call was completed or after it has thrown an error
(Process halted with error code)
Additional context
- In Rollup/Vite realm
buildStartis async and can be used to perform initial initialisation fortransformhook invocations. transformhook seems to be correctly async, which means you can await forbuildStartfulfillment in it, which involves moving async logic ofbuildStartto 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
N/A.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the StackBlitz reproduction and run pnpm test and pnpm start to observe the webpack hook order. Trace the webpack adapter's buildStart and transform handling, then ensure transform does not run until buildStart's asynchronous work completes; the reproduction should complete without the ordering error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100