Skip to content

Commit f40257c

Browse files
committed
merge external-package-resolution and internal-module-resolution example with guidelines on readme
1 parent dc74937 commit f40257c

File tree

20 files changed

+58
-47
lines changed

20 files changed

+58
-47
lines changed

fixtures/vitest-pool-workers-examples/external-package-resolution/test/index.spec.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

fixtures/vitest-pool-workers-examples/external-package-resolution/test/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

fixtures/vitest-pool-workers-examples/internal-module-resolution/README.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

fixtures/vitest-pool-workers-examples/internal-module-resolution/test/index.spec.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

fixtures/vitest-pool-workers-examples/internal-module-resolution/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

fixtures/vitest-pool-workers-examples/internal-module-resolution/vitest.config.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

fixtures/vitest-pool-workers-examples/internal-module-resolution/wrangler.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# ⚡ module-resolution
2+
3+
This fixture demonstrates that the Vitest integration correctly resolves modules, including:
4+
5+
- A CommonJS package that requires a directory rather than a specific file.
6+
- A package without a main entrypoint or with browser field mapping, handled via [Dependency Pre-Bundling](#dependency-pre-bundling).
7+
8+
## Dependency Pre-Bundling
9+
10+
[Dependency Pre-Bundling](https://vite.dev/guide/dep-pre-bundling) is a Vite feature that converts dependencies shipped as CommonJS or UMD into ESM. If you encounter module resolution issues—such as: `Error: Cannot use require() to import an ES Module` or `Error: No such module`—you can pre-bundle these dependencies using the [deps.optimizer](https://vitest.dev/config/#deps-optimizer) option:
11+
12+
```ts
13+
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
14+
15+
export default defineWorkersConfig({
16+
test: {
17+
deps: {
18+
optimizer: {
19+
ssr: {
20+
enabled: true,
21+
include: ["your-package-name"],
22+
},
23+
},
24+
},
25+
poolOptions: {
26+
workers: {
27+
// ...
28+
},
29+
},
30+
},
31+
});
32+
```
33+
34+
See our [vitest config](./vitest.config.ts) for an example of how we pre-bundled `discord-api-types/v10` and `@microlabs/otel-cf-workers`.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Toucan } from "toucan-js";
2-
// Test pre-bundling dependency relies on exports field without a default entrypoint
2+
// Testing dependency without a main entrypoint
33
// @see https://github.com/cloudflare/workers-sdk/issues/6591
44
import "discord-api-types/v10";
5-
// Test pre-bundling dependencies with browser field mapping
5+
// Testing dependency with browser field mapping
66
// @see https://github.com/cloudflare/workers-sdk/issues/6581
77
import "@microlabs/otel-cf-workers";
88

0 commit comments

Comments
 (0)