@cloudflare/vitest-pool-workers: "wrapped binding module can't be resolved (internal modules only); moduleName = miniflare-internal:wrapped:__WRANGLER_EXTERNAL_AI_WORKER" with an [ai] binding
Run tests against a wrangler config that has no [ai] block, and make the code handle a missing env.AI (or inject a stub). We copied wrangler.toml to wrangler.test.toml without [ai] and pointed the pool at it:
// vitest.config.ts
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
export default defineWorkersConfig({
test: { poolOptions: { workers: { wrangler: { configPath: './wrangler.test.toml' } } } },
});After that the D1/KV/R2/Durable Object tests ran (6/6 passing).
Symptom with @cloudflare/vitest-pool-workers 0.5.x and wrangler 3.114: workerd prints error: wrapped binding module can't be resolved (internal modules only); moduleName = miniflare-internal:wrapped:__WRANGLER_EXTERNAL_AI_WORKER. Then MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start and Test Files no tests, so it looks like a broken install, not a binding problem. The cause: Workers AI has no local simulator. In wrangler dev it is proxied to Cloudflare (which needs a login), and this older test pool can't wire up that proxy at all. Newer releases (vitest-pool-workers 0.23 / wrangler 4.x in Nov 2026) handle remote bindings differently. Even if that works, it will still need Cloudflare credentials, so keep AI out of unit tests and mock it.
Also note: npm test running plain vitest stays in watch mode inside a container ("Watching for file changes..."). Use vitest --run in scripts and CI.