fix(dev): stop @shopify/hydrogen watch from racing example bundlers - #3826
Closed
div-cowboy wants to merge 1 commit into
Closed
fix(dev): stop @shopify/hydrogen watch from racing example bundlers#3826div-cowboy wants to merge 1 commit into
div-cowboy wants to merge 1 commit into
Conversation
Running `pnpm dev` (or `dev:next`/`dev:rr`) spewed a wall of transient "Module not found: Can't resolve '@shopify/hydrogen'" errors at startup. Cause: those scripts scheduled both `@shopify/hydrogen#build` (one-shot) and `@shopify/hydrogen#dev` (`tsdown --watch`). The watch rewrites dist/ on startup while the example bundlers (Turbopack, Vite) are reading it, so they momentarily see partial/empty module files. The errors are transient (the app still serves once the watch settles), but they look like a broken setup. Confirmed the watch alone causes it even when `#build` is a cache hit, so serializing the two doesn't help — the concurrent watch has to go. Scope the dev scripts to the examples so turbo still builds @shopify/hydrogen once (via `dependsOn: ["^build"]`) but does not run its watch alongside them: - `dev` -> `turbo run dev --filter='./examples/*'` - `dev:next`/`dev:rr` -> drop the trailing `...` (dependency) selector `dev:pkgs` still watches the packages for SDK development; run it alongside an example only when you're actively editing the SDK. Verified cold (dist removed, caches cleared): `pnpm dev:next` now logs 0 module-not-found errors (was 22), with @shopify/hydrogen#build running and #dev (watch) not. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
I have signed the CLA! |
div-cowboy
added a commit
to div-cowboy/hydrogen
that referenced
this pull request
Jun 30, 2026
`pnpm dev` runs `@shopify/hydrogen#build` (one-shot, via turbo `^build`) and then `@shopify/hydrogen#dev` (`tsdown --watch`). The watch's default startup clean wipes the just-built `dist/` while the example bundlers are reading it, spewing transient "Module not found: Can't resolve '@shopify/hydrogen'" at every example. Disable clean in `--watch` mode only: `dist/` stays populated from the build, rolldown writes each output atomically, so example bundlers always resolve a complete module. Production builds still clean; SDK hot reload is preserved (verified: edit src -> tsdown rebuilds -> example reloads). This replaces the dev-script workaround from Shopify#3826 (which removed the watch and so lost SDK hot reload). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Superseded by #3825. That PR fixes the same |
div-cowboy
added a commit
to div-cowboy/hydrogen
that referenced
this pull request
Jul 31, 2026
`pnpm dev` runs `@shopify/hydrogen#build` (one-shot, via turbo `^build`) and then `@shopify/hydrogen#dev` (`tsdown --watch`). The watch's default startup clean wipes the just-built `dist/` while the example bundlers are reading it, spewing transient "Module not found: Can't resolve '@shopify/hydrogen'" at every example. Disable clean in `--watch` mode only: `dist/` stays populated from the build, rolldown writes each output atomically, so example bundlers always resolve a complete module. Production builds still clean; SDK hot reload is preserved (verified: edit src -> tsdown rebuilds -> example reloads). This replaces the dev-script workaround from Shopify#3826 (which removed the watch and so lost SDK hot reload). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running
pnpm dev(andpnpm dev:next/pnpm dev:rr) prints a wall of transient errors at startup:The app still serves once startup settles, but it looks broken and is alarming.
Cause
Those scripts schedule both
@shopify/hydrogen#build(one-shot) and@shopify/hydrogen#dev(tsdown --watch). The watch rewritesdist/on startup while the example bundlers (Turbopack, Vite) are reading it, so they momentarily resolve partial/empty module files → "Module not found".I confirmed:
dist/files never disappear (high-frequency polling shows 0 missing); it's mid-write partial reads.@shopify/hydrogen#buildis a turbo cache hit, so serializing build→dev wouldn't fix it. The concurrent watch has to be removed from the examples' dev path.Fix
Scope the dev scripts to the examples. Turbo still builds
@shopify/hydrogenonce viadependsOn: ["^build"], but no longer runs its watch alongside the examples:dev:pkgsstill watches./packages/*for SDK development — run it alongside an example only when actively editing the SDK. This also makespnpm devmatch its README description ("every example's dev server in parallel").Trade-off
Editing
@shopify/hydrogensource no longer hot-rebuilds into a running example underpnpm dev(usepnpm dev:pkgsfor that). A future improvement could restore concurrent SDK-watch + examples by making the SDK build writedist/atomically (temp + rename) so bundlers never observe a partial file.Verification
Cold (
packages/hydrogen/distremoved,.nextand turbo cache cleared):Turbo dry-run confirms
@shopify/hydrogen#buildis still scheduled and@shopify/hydrogen#devis dropped.🤖 Generated with Claude Code