Skip to content
Discussion options

You must be logged in to vote

The CDS server loads your service .ts files with its own runtime loader, not through vitest's transform, so vitest only transforms the test files. Your srv/server.ts (and admin-service.ts) do the extensionless import { genid } from "./utils/id", and with no TS loader active for that load Node can't resolve ./utils/id.ts, hence Cannot find module .../srv/utils/id imported from .../srv/server.ts. cds w works because it runs under tsx, which is the active loader there.

Fix: register tsx for the vitest process too, so CDS's loads resolve .ts:

// package.json
"scripts": { "test": "NODE_OPTIONS='--import tsx' vitest" }

I reproduced it on your sample repo (cds 9, vitest 4): without the flag cds.…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@stockbal
Comment options

Answer selected by stockbal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants