GitHub - iterate-com/cf-vitest-repro

Does anyone know how to avoid this issue when using vitest workspaces? https://github.com/iterate-com/cf-vitest-repro
GitHub
GitHub - iterate-com/cf-vitest-repro
Contribute to iterate-com/cf-vitest-repro development by creating an account on GitHub.
1 Reply
jonast
jonastOP2w ago
Simple repro of vitest and workers.

In src/workers we have cloudflare specific code with the corresponding tests.

We have a vitest workspace setup to target only this directory.

In src/lib we have Node.js code. The vitest workspace node is setup to target this, but not the workers directory.

Run pnpm vitest - see error:

FAIL workers src/workers/index.test.ts [ src/workers/index.test.ts ]
SyntaxError: The requested module 'node:fs' does not provide an export named 'ReadStream'
Remove the openai usage in src/workers/index.ts. Then re-run the tests:

[vpw:inf] Starting isolated runtimes for 0...
✓ node src/lib/greet.test.ts (1 test) 3ms
✓ workers src/workers/index.test.ts (1 test) 6ms
It works!
Simple repro of vitest and workers.

In src/workers we have cloudflare specific code with the corresponding tests.

We have a vitest workspace setup to target only this directory.

In src/lib we have Node.js code. The vitest workspace node is setup to target this, but not the workers directory.

Run pnpm vitest - see error:

FAIL workers src/workers/index.test.ts [ src/workers/index.test.ts ]
SyntaxError: The requested module 'node:fs' does not provide an export named 'ReadStream'
Remove the openai usage in src/workers/index.ts. Then re-run the tests:

[vpw:inf] Starting isolated runtimes for 0...
✓ node src/lib/greet.test.ts (1 test) 3ms
✓ workers src/workers/index.test.ts (1 test) 6ms
It works!

Did you find this page helpful?