Cannot find module 'cloudflare:test' or its corresponding type declarations

I created a project with the bun hono template and installed @Cloudflare/vitest-pool-workers. Afterwards, the test code was not able to find the module.

// test/index.test.ts
import app from '../src/index'
import { env } from 'cloudflare:test' // << not found error
import { expect, describe, it } from 'vitest'

describe('Test the application', () => {
    it('Should return 200 response', async () => {
        const res = await app.request('/', {}, env)
        expect(res.status).toBe(200)
    })
    it('should return 404 for unknown routes', async () => {
        const res = await app.request('/unknown', {});
        expect(res.status).toBe(404);
    })

// package.json
{
  "name": "my-app",
  "scripts": {
    "dev": "wrangler dev",
    "deploy": "wrangler deploy --minify"
  },
  "dependencies": {
    "hono": "^4.6.16"
  },
  "devDependencies": {
    "@cloudflare/vitest-pool-workers": "^0.6.0",
    "@cloudflare/workers-types": "^4.20250109.0",
    "vitest": "2.1.8"
  }
}

// vitest.config.ts
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';

export default defineWorkersConfig({
  test: {
    poolOptions: {
      workers: {
        wrangler: { configPath: './wrangler.toml' },
      },
    },
  },
});

// test/tsconfig.json
{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "moduleResolution": "bundler",
    "types": [
      "@cloudflare/workers-types/experimental",
      "@cloudflare/vitest-pool-workers"
    ]
  },
  "include": ["./**/*.ts", "../src/env.d.ts"]
}
Was this page helpful?