Hi, I am implementing a CF <manual edge worker> in...
# ask-questions
a
Hi, I am implementing a CF manual edge worker in typescript. However, when I run tests (
npm run test
which runs
vitest
) I am getting an error:
FAIL  test/index.spec.js [ test/index.spec.js ]
TypeError: Cannot use require() to import an ES Module.
❯ node_modules/@growthbook/edge-utils/dist/app.js?mf_vitest_no_cjs_esm_shim:16:22
❯ node_modules/@growthbook/edge-utils/dist/index.js?mf_vitest_no_cjs_esm_shim:7:13
It seems some internals growthbook libs use
require
which doesn't work with vitest, any suggestions how to fix this?
f
@happy-autumn-40938?
a
My worker index.ts has only these imports:
Copy code
import { GrowthBook } from "@growthbook/growthbook";
import { getPayloadFromKV } from "@growthbook/edge-cloudflare";
f
@kind-autumn-215
h
I don't have an answer on how to make CJS play nicely with vitest in this scenario, but I can look into it. Possibly dual export to ESM + CJS. I have had some success in the past via forcing modules / renaming test runners to
.mjs
😿 1
b
Could you perhaps recommend a test suite which would not have such issues with growthbook?
@happy-autumn-40938 in case this got burried
h
You could perhaps try jest, although I don't particularly love recommending that. I'll be working on a new Edge SDK build over the next couple of weeks and will do some testing in vitest at that time. This may mean that the SDK will be dual-packaged for CJS and ESM.
🙌 1