Skip to content

[workers-playground] Fix Vite 8 / rolldown crash: TypeError: createRenderer is not a function#13105

Merged
petebacondarwin merged 1 commit intomainfrom
workers-playground-fix-vite8-style-provider
Mar 30, 2026
Merged

[workers-playground] Fix Vite 8 / rolldown crash: TypeError: createRenderer is not a function#13105
petebacondarwin merged 1 commit intomainfrom
workers-playground-fix-vite8-style-provider

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin commented Mar 28, 2026

Fixes #[insert GH or internal issue link(s)].

@cloudflare/style-provider ships a hybrid ESM+CJS package: its es/ directory contains files that are nominally ESM but internally use require(). Vite 8's new bundler (rolldown) mishandles this pattern and generates an anonymous, unreachable module initializer, leaving createRenderer as undefined at runtime:

Uncaught TypeError: createRenderer is not a function
    at getRenderer (index-B9Sbpvoo.js:42950:28)

Rolldown wraps the module in a lazy __esmMin thunk but discards the return value (assigns it to no variable), so init_createRenderer() is never called and the createRenderer variable stays undefined.

The fix aliases @cloudflare/style-provider to its CJS build (lib/index.js) in vite.config.ts. Rolldown handles plain CJS correctly via its interop layer, avoiding the broken initializer entirely.

Also replaces base: '/playground' with assetsDir: 'playground/assets': using base causes Vite to write assets to dist/assets/ but reference them as /playground/assets/ in the HTML, which breaks after Wrangler uploads them. Keeping assets under dist/playground/assets/ means the paths in the HTML match their actual deployed location.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows: ran pnpm vite build && pnpm vite preview and confirmed the TypeError is gone
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal build config change only

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@petebacondarwin petebacondarwin requested a review from a team as a code owner March 28, 2026 17:47
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 28, 2026

🦋 Changeset detected

Latest 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

@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 28, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Mar 28, 2026

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:

  1. The CJS alias for @cloudflare/style-provider is a valid workaround for a Vite 8/rolldown bug.
  2. The baseassetsDir switch correctly fixes the asset path mismatch.

LGTM

github run

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 28, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13105

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13105

miniflare

npm i https://pkg.pr.new/miniflare@13105

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13105

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13105

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13105

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13105

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13105

wrangler

npm i https://pkg.pr.new/wrangler@13105

commit: 5e5489f

…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.
@petebacondarwin petebacondarwin force-pushed the workers-playground-fix-vite8-style-provider branch from 5cdcc7f to 5e5489f Compare March 28, 2026 21:45
@github-actions
Copy link
Copy Markdown
Contributor

✅ All changesets look good

Comment thread packages/workers-playground/vite.config.ts
@jamesopstad
Copy link
Copy Markdown
Contributor

This feels like it should be fixed in either @cloudflare/style-provider or Rolldown, depending on where you believe the bug to be.

Copy link
Copy Markdown
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this should be fixed upstream, but this seems fine as a stopgap

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Mar 30, 2026
@petebacondarwin
Copy link
Copy Markdown
Contributor Author

petebacondarwin commented Mar 30, 2026

__esmMin

I think the bug is reported here rolldown/rolldown#8777
and a fix was attempted but closed here rolldown/rolldown#8922

But meanwhile...

@petebacondarwin petebacondarwin merged commit ff41b07 into main Mar 30, 2026
55 of 59 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Mar 30, 2026
@petebacondarwin petebacondarwin deleted the workers-playground-fix-vite8-style-provider branch March 30, 2026 12:33
NuroDev pushed a commit that referenced this pull request Mar 30, 2026
@jamesopstad
Copy link
Copy Markdown
Contributor

__esmMin

I think the bug is reported here rolldown/rolldown#8777 and a fix was attempted but closed here rolldown/rolldown#8922

But meanwhile...

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.

@petebacondarwin
Copy link
Copy Markdown
Contributor Author

__esmMin

I think the bug is reported here rolldown/rolldown#8777 and a fix was attempted but closed here rolldown/rolldown#8922
But meanwhile...

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants