Skip to content

Conversation

@ksawaneh
Copy link

Fixes #9822.

@cloudflare/vitest-pool-workers's module fallback service returned .json files as commonJsModule source. When a CommonJS dependency does require("./data.json"), workerd would try to parse the JSON as JavaScript and throw SyntaxError: Unexpected token ':'.

This change:

  • Extends fallback resolution to consider .json
  • Serves .json as an ES module wrapper that exports JSON.parse(...) (avoids object-literal __proto__ prototype mutation)
  • Adds a regression test covering CommonJS JSON require
  • Adds a changeset for @cloudflare/vitest-pool-workers

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:

Commands run:

  • pnpm check

  • pnpm --filter @cloudflare/vitest-pool-workers run check:lint

  • pnpm --filter @cloudflare/vitest-pool-workers run check:type

  • pnpm exec vitest run test/json-require.test.ts (from packages/vitest-pool-workers)

  • Public documentation

    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal module fallback behavior + regression test, no docs change required

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

/_/
( o.o )

^ <

@ksawaneh ksawaneh requested a review from a team as a code owner January 14, 2026 13:07
@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2026

🦋 Changeset detected

Latest commit: 4a3d561

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

require-ing a json file breaks vitest

1 participant