Hey folks, looking at getting into using

Hey folks, looking at getting into using vitest for testing a discord bot but having problems when it tries to import discord-api-types. Of note, i tried this without the wrangler integration and just using vitest on its own and the test is fine, its only when i configure vitest with the wrangler integration that it fails.
FAIL src/impl.test.mts [ src/impl.test.mts ]
Error: No such module "C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.js".
imported from "C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs"
FAIL src/impl.test.mts [ src/impl.test.mts ]
Error: No such module "C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.js".
imported from "C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs"
8 Replies
soundmanD
soundmanDOP4d ago
GitHub
GitHub - davidhouweling/vitest-wrangler-discord-api-types: Example ...
Example issue of vitest wrangler discord-api-types - davidhouweling/vitest-wrangler-discord-api-types
soundmanD
soundmanDOP4d ago
it is very much the same as https://discord.com/channels/595317990191398933/1218150105777963101/1218598314405007370 in the example repo, i've added in NODE_DEBUG=vitest-pool-workers:module-fallback environment variable and this is the output... part 1...
VITEST-POOL-WORKERS:MODULE-FALLBACK 58168: import("C:/git/vitest-wrangler-discord-api-types/node_modules/vite-node/dist/file:/C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs") relative to C:/git/vitest-wrangler-discord-api-types/node_modules/vite-node/dist/client.mjs: redirect: C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs
VITEST-POOL-WORKERS:MODULE-FALLBACK 58168: import("C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs") relative to C:/git/vitest-wrangler-discord-api-types/node_modules/vite-node/dist/client.mjs: esm: C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs
VITEST-POOL-WORKERS:MODULE-FALLBACK 58168: import("C:/git/vitest-wrangler-discord-api-types/node_modules/vite-node/dist/file:/C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs") relative to C:/git/vitest-wrangler-discord-api-types/node_modules/vite-node/dist/client.mjs: redirect: C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs
VITEST-POOL-WORKERS:MODULE-FALLBACK 58168: import("C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs") relative to C:/git/vitest-wrangler-discord-api-types/node_modules/vite-node/dist/client.mjs: esm: C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs
part 2...
VITEST-POOL-WORKERS:MODULE-FALLBACK 58168: import("C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.js") relative to C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs: error: Error: Parse error @7:1:8
at Module.parse (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/cjs-module-lexer/dist/lexer.mjs:2:381)
at getCjsNamedExports (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:703:49)
at getCjsNamedExports (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:719:35)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async load (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:940:24)
at async handleModuleFallbackRequest (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:977:12)
at async #handleLoopback (C:\git\vitest-wrangler-discord-api-types\node_modules\miniflare\dist\src\index.js:9619:20) {
idx: 7,
code: 'ERR_LEXER_ESM_SYNTAX'
}
workerd/server/server.c++:3059: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=%2FC%3A%2Fgit%2Fvitest-wrangler-discord-api-types%2Fnode_modules%2Fdiscord-api-types%2Fv10.js&referrer=%2FC%3A%2Fgit%2Fvitest-wrangler-discord-api-types%2Fnode_modules%2Fdiscord-api-types%2Fv10.mjs&rawSpecifier=.%2Fv10.js
VITEST-POOL-WORKERS:MODULE-FALLBACK 58168: import("C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.js") relative to C:/git/vitest-wrangler-discord-api-types/node_modules/discord-api-types/v10.mjs: error: Error: Parse error @7:1:8
at Module.parse (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/cjs-module-lexer/dist/lexer.mjs:2:381)
at getCjsNamedExports (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:703:49)
at getCjsNamedExports (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:719:35)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async load (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:940:24)
at async handleModuleFallbackRequest (file:///C:/git/vitest-wrangler-discord-api-types/node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:977:12)
at async #handleLoopback (C:\git\vitest-wrangler-discord-api-types\node_modules\miniflare\dist\src\index.js:9619:20) {
idx: 7,
code: 'ERR_LEXER_ESM_SYNTAX'
}
workerd/server/server.c++:3059: error: Fallback service failed to fetch module; payload = ; spec = /?specifier=%2FC%3A%2Fgit%2Fvitest-wrangler-discord-api-types%2Fnode_modules%2Fdiscord-api-types%2Fv10.js&referrer=%2FC%3A%2Fgit%2Fvitest-wrangler-discord-api-types%2Fnode_modules%2Fdiscord-api-types%2Fv10.mjs&rawSpecifier=.%2Fv10.js
i'm using discord-api-types fine in the actual application itself, so it feels quite wrong that this is an issue just with testing.
userzach
userzach4d ago
Agree. I'm struggling with this too wrangler applies the compatibility module transformations but vitest integration does not, suggesting different module resolution for the vitest integration
soundmanD
soundmanDOP2d ago
raised an issue in github so that it can appropriately be tracked as it doesn't look like we are getting any traction here: https://github.com/cloudflare/workers-sdk/issues/7323
GitHub
🐛 BUG: Vitest integration does not work with discord-api-types · Is...
Which Cloudflare product(s) does this pertain to? Workers Vitest Integration What version(s) of the tool(s) are you using? 0.5.28 [@cloudflare/vitest-pool-workers] What version of Node are you usin...
userzach
userzach2d ago
Agree. I did the same. Do you think trying to test with Miniflare 2 would be worth it? I'm evaluating that now for myself.
soundmanD
soundmanDOP2d ago
i actually came to the same conclusion as well, as in taking a crack at using minflare on its own and just pulling what i need in a test setup rather than trying to set up a global approach
userzach
userzach2d ago
Beware though:
Warning This repository is for Miniflare 2, which is only receiving critical security updates. Miniflare 2 simulated the Workers runtime and the rest of the Cloudflare developer platform using Node.js. New versions of Miniflare can be found in the workers-sdk repository, and use the open-sourced Workers runtime workerd. This practically eliminates behaviour mismatches between development and production deployments. We recommend you migrate to Miniflare 3 now if you can. Whilst Miniflare 3 supports most of Miniflare 2's features, one key omission is the unit testing environment. We're actively working on adding support for this to Miniflare 3. Once this is supported, we're planning to deprecate Miniflare 2 and archive this repository.
soundmanD
soundmanDOP2d ago
thanks. i am taking a crack at it with miniflare 3. i'll see what i come up with...
Want results from more Discord servers?
Add your server