Skip to content

[vitest-pool-workers] Allow .wasm files to be imported as .wasm?module#11094

Merged
penalosa merged 4 commits into
cloudflare:mainfrom
bbridges:vitest-pool-workers-wasm-module-fix
May 7, 2026
Merged

[vitest-pool-workers] Allow .wasm files to be imported as .wasm?module#11094
penalosa merged 4 commits into
cloudflare:mainfrom
bbridges:vitest-pool-workers-wasm-module-fix

Conversation

@bbridges

@bbridges bbridges commented Oct 24, 2025

Copy link
Copy Markdown

When loading WASM in module-fallback.ts in vitest-pool-workers, this change trims off a ?module suffix if provided from the module file path. Similar behavior is handled in vite-plugin-cloudflare, where it will trim this suffix.

I ran into an issue using Cloudflare D1 with Prisma since the client generated using

generator client {
  provider = "prisma-client"
  output   = "../src/generated/prisma"
  runtime  = "workerd"
}

included an import import("./query_engine_bg.wasm?module") which could be handled running wrangler dev but couldn't be handled by vitest-pools-workers since it would fail to resolve the module.

A catch with this is if someone is trying to literally import a WASM file with a .wasm?module extension on disk, then it can't be loaded this way.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bugfix

Open with Devin
@bbridges bbridges requested a review from a team as a code owner October 24, 2025 18:38
@changeset-bot

changeset-bot Bot commented Oct 24, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9fa1d9b

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

devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new

pkg-pr-new Bot commented Feb 10, 2026

Copy link
Copy Markdown
create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@11094

wrangler

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

commit: 9fa1d9b

@petebacondarwin petebacondarwin force-pushed the vitest-pool-workers-wasm-module-fix branch from 5b49f2b to d964686 Compare March 14, 2026 16:40
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/vitest-pool-workers/src/pool/module-fallback.ts: [@cloudflare/wrangler]
@penalosa penalosa force-pushed the vitest-pool-workers-wasm-module-fix branch from d964686 to aac0d29 Compare March 20, 2026 20:03
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/vitest-pool-workers/src/pool/module-fallback.ts: [@cloudflare/wrangler]
devin-ai-integration[bot]

This comment was marked as resolved.

@petebacondarwin petebacondarwin requested review from a team and emily-shen and removed request for a team April 15, 2026 06:51
@edmundhung edmundhung requested review from edmundhung and removed request for emily-shen May 1, 2026 14:27
@workers-devprod

workers-devprod commented May 1, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/quiet-tools-press.md: [@cloudflare/wrangler]
  • fixtures/vitest-pool-workers-examples/module-resolution/README.md: [@cloudflare/wrangler]
  • fixtures/vitest-pool-workers-examples/module-resolution/test/index.spec.ts: [@cloudflare/wrangler]
  • fixtures/vitest-pool-workers-examples/module-resolution/vendor/wasm-module-dep/add.wasm: [@cloudflare/wrangler]
  • fixtures/vitest-pool-workers-examples/module-resolution/vendor/wasm-module-dep/index.d.mts: [@cloudflare/wrangler]
  • fixtures/vitest-pool-workers-examples/module-resolution/vendor/wasm-module-dep/index.mjs: [@cloudflare/wrangler]
  • fixtures/vitest-pool-workers-examples/module-resolution/vendor/wasm-module-dep/package.json: [@cloudflare/wrangler]
  • fixtures/vitest-pool-workers-examples/package.json: [@cloudflare/wrangler]
  • fixtures/vitest-pool-workers-examples/web-assembly/src/index.ts: [@cloudflare/wrangler]
  • fixtures/vitest-pool-workers-examples/web-assembly/src/wasm-shim.d.ts: [@cloudflare/wrangler]
  • packages/vitest-pool-workers/src/pool/cloudflare-pool-worker.ts: [@cloudflare/wrangler]
  • pnpm-lock.yaml: [@cloudflare/wrangler]
@edmundhung edmundhung force-pushed the vitest-pool-workers-wasm-module-fix branch from 92330a5 to ec1ed40 Compare May 5, 2026 11:02
devin-ai-integration[bot]

This comment was marked as resolved.

@edmundhung edmundhung force-pushed the vitest-pool-workers-wasm-module-fix branch 2 times, most recently from f2b25f9 to e512891 Compare May 5, 2026 12:05
Externalize .wasm?module specifiers through the fallback service and normalize Vite @fs paths so dependency-local WASM modules resolve under the Vitest pool.
@edmundhung edmundhung force-pushed the vitest-pool-workers-wasm-module-fix branch from e512891 to 9fa1d9b Compare May 5, 2026 12:12
Comment thread packages/vitest-pool-workers/src/pool/cloudflare-pool-worker.ts
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk May 7, 2026
@penalosa penalosa merged commit 9367435 into cloudflare:main May 7, 2026
57 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk May 7, 2026
tahmid-23 added a commit to tahmid-23/workers-sdk that referenced this pull request Jun 5, 2026
…deps

Previously, only literal `await import("./x.wasm?module")` specifiers were
rewritten through the static analysis path added in cloudflare#11094. CommonJS
dependencies that use `require("./x.wasm?module")` reach the module-fallback
service at runtime, where the `?module` suffix went unhandled. The fallback
either failed with `No such module "<abs>/x.wasm?module"` or, when a
CompiledWasm rule was configured, attempted to evaluate the WebAssembly bytes
as JavaScript.

These `require()`s work in deployed workers because esbuild's bundler
statically rewrites them into ES dynamic imports. vitest-pool-workers'
Vite-based pipeline doesn't do that rewrite and instead defers to the
module-fallback at runtime.

The module-fallback now strips `?module` from the resolved target and
synthesizes a CommonJS wrapper that re-`require`s the underlying `.wasm` by
absolute path, exposing it on `default` to match what workerd produces for
CompiledWasm modules.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
tahmid-23 added a commit to tahmid-23/workers-sdk that referenced this pull request Jun 8, 2026
…deps

Previously, only literal `await import("./x.wasm?module")` specifiers were
rewritten through the static analysis path added in cloudflare#11094. CommonJS
dependencies that use `require("./x.wasm?module")` reach the module-fallback
service at runtime, where the `?module` suffix went unhandled. The fallback
either failed with `No such module "<abs>/x.wasm?module"` or, when a
CompiledWasm rule was configured, attempted to evaluate the WebAssembly bytes
as JavaScript.

These `require()`s work in deployed workers because esbuild's bundler
statically rewrites them into ES dynamic imports. vitest-pool-workers'
Vite-based pipeline doesn't do that rewrite and instead defers to the
module-fallback at runtime.

The module-fallback now strips `?module` from the resolved target and
synthesizes a CommonJS wrapper that re-`require`s the underlying `.wasm` by
absolute path, exposing it on `default` to match what workerd produces for
CompiledWasm modules.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
tahmid-23 added a commit to tahmid-23/workers-sdk that referenced this pull request Jun 15, 2026
…deps

Previously, only literal `await import("./x.wasm?module")` specifiers were
rewritten through the static analysis path added in cloudflare#11094. CommonJS
dependencies that use `require("./x.wasm?module")` reach the module-fallback
service at runtime, where the `?module` suffix went unhandled. The fallback
either failed with `No such module "<abs>/x.wasm?module"` or, when a
CompiledWasm rule was configured, attempted to evaluate the WebAssembly bytes
as JavaScript.

These `require()`s work in deployed workers because esbuild's bundler
statically rewrites them into ES dynamic imports. vitest-pool-workers'
Vite-based pipeline doesn't do that rewrite and instead defers to the
module-fallback at runtime.

The module-fallback now strips `?module` from the resolved target and
synthesizes a CommonJS wrapper that re-`require`s the underlying `.wasm` by
absolute path, exposing it on `default` to match what workerd produces for
CompiledWasm modules.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
tahmid-23 added a commit to tahmid-23/workers-sdk that referenced this pull request Jun 15, 2026
…deps

Previously, only literal `await import("./x.wasm?module")` specifiers were
rewritten through the static analysis path added in cloudflare#11094. CommonJS
dependencies that use `require("./x.wasm?module")` reach the module-fallback
service at runtime, where the `?module` suffix went unhandled. The fallback
either failed with `No such module "<abs>/x.wasm?module"` or, when a
CompiledWasm rule was configured, attempted to evaluate the WebAssembly bytes
as JavaScript.

These `require()`s work in deployed workers because esbuild's bundler
statically rewrites them into ES dynamic imports. vitest-pool-workers'
Vite-based pipeline doesn't do that rewrite and instead defers to the
module-fallback at runtime.

The module-fallback now strips `?module` from the resolved target and
synthesizes a CommonJS wrapper that re-`require`s the underlying `.wasm` by
absolute path, exposing it on `default` to match what workerd produces for
CompiledWasm modules.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
emily-shen added a commit to tahmid-23/workers-sdk that referenced this pull request Jun 16, 2026
…deps

Previously, only literal `await import("./x.wasm?module")` specifiers were
rewritten through the static analysis path added in cloudflare#11094. CommonJS
dependencies that use `require("./x.wasm?module")` reach the module-fallback
service at runtime, where the `?module` suffix went unhandled. The fallback
either failed with `No such module "<abs>/x.wasm?module"` or, when a
CompiledWasm rule was configured, attempted to evaluate the WebAssembly bytes
as JavaScript.

These `require()`s work in deployed workers because esbuild's bundler
statically rewrites them into ES dynamic imports. vitest-pool-workers'
Vite-based pipeline doesn't do that rewrite and instead defers to the
module-fallback at runtime.

The module-fallback now strips `?module` from the resolved target and
synthesizes a CommonJS wrapper that re-`require`s the underlying `.wasm` by
absolute path, exposing it on `default` to match what workerd produces for
CompiledWasm modules.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
emily-shen added a commit to tahmid-23/workers-sdk that referenced this pull request Jun 29, 2026
…deps

Previously, only literal `await import("./x.wasm?module")` specifiers were
rewritten through the static analysis path added in cloudflare#11094. CommonJS
dependencies that use `require("./x.wasm?module")` reach the module-fallback
service at runtime, where the `?module` suffix went unhandled. The fallback
either failed with `No such module "<abs>/x.wasm?module"` or, when a
CompiledWasm rule was configured, attempted to evaluate the WebAssembly bytes
as JavaScript.

These `require()`s work in deployed workers because esbuild's bundler
statically rewrites them into ES dynamic imports. vitest-pool-workers'
Vite-based pipeline doesn't do that rewrite and instead defers to the
module-fallback at runtime.

The module-fallback now strips `?module` from the resolved target and
synthesizes a CommonJS wrapper that re-`require`s the underlying `.wasm` by
absolute path, exposing it on `default` to match what workerd produces for
CompiledWasm modules.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This was referenced Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants