[workers-playground] Fix Vite 8 / rolldown crash: TypeError: createRenderer is not a function#13105
Conversation
🦋 Changeset detectedLatest commit: 5e5489f The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
|
I see a minor double-space on line 32 ("would cause"), but that's purely cosmetic in a comment — not actionable per my guidelines. The logic and approach are sound. The change is clean and well-reasoned. Both fixes address real issues:
LGTM |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
…tyle-provider to its CJS build @cloudflare/style-provider ships a hybrid ESM+CJS package (es/ files that use require() internally). Vite 8's new rolldown bundler mishandles this pattern and generates an anonymous, unreachable module initializer, leaving createRenderer as undefined at runtime: TypeError: createRenderer is not a function Fix by aliasing @cloudflare/style-provider to its CJS entry (lib/index.js) in vite.config.ts. Rolldown handles plain CJS correctly via its interop layer, so this avoids the broken initializer entirely. Also replace base: '/playground' with assetsDir: 'playground/assets' so that the deployed asset paths match what Wrangler uploads.
5cdcc7f to
5e5489f
Compare
|
✅ All changesets look good |
|
This feels like it should be fixed in either |
penalosa
left a comment
There was a problem hiding this comment.
I agree that this should be fixed upstream, but this seems fine as a stopgap
I think the bug is reported here rolldown/rolldown#8777 But meanwhile... |
…nderer is not a function (#13105)
That's fine but in these cases we should reference the upstream issue in the code with a reminder to remove the workaround when it's no longer needed. |
Yes, you're right. Sorry. I'll track this and hopefully it will be released while I am still holding it in memory 😄 |
Fixes #[insert GH or internal issue link(s)].
@cloudflare/style-providerships a hybrid ESM+CJS package: itses/directory contains files that are nominally ESM but internally userequire(). Vite 8's new bundler (rolldown) mishandles this pattern and generates an anonymous, unreachable module initializer, leavingcreateRendererasundefinedat runtime:Rolldown wraps the module in a lazy
__esmMinthunk but discards the return value (assigns it to no variable), soinit_createRenderer()is never called and thecreateRenderervariable staysundefined.The fix aliases
@cloudflare/style-providerto its CJS build (lib/index.js) invite.config.ts. Rolldown handles plain CJS correctly via its interop layer, avoiding the broken initializer entirely.Also replaces
base: '/playground'withassetsDir: 'playground/assets': usingbasecauses Vite to write assets todist/assets/but reference them as/playground/assets/in the HTML, which breaks after Wrangler uploads them. Keeping assets underdist/playground/assets/means the paths in the HTML match their actual deployed location.pnpm vite build && pnpm vite previewand confirmed the TypeError is goneA picture of a cute animal (not mandatory, but encouraged)