vite-tsconfig-paths throws error when used in Worker vitest config

Hello, I'm using custom paths inside of my tsconfig, I've tried to make Vitest compatible with them using the vite-tsconfig-paths plugin however it consistently gives me this error ..
✘ [ERROR] "vite-tsconfig-paths" resolved to an ESM file. ESM file cannot be loaded by `require`. See https://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details. [plugin externalize-deps]

../node_modules/vite/node_modules/esbuild/lib/main.js:1225:27:
1225 │ let result = await callback({
╵ ^
✘ [ERROR] "vite-tsconfig-paths" resolved to an ESM file. ESM file cannot be loaded by `require`. See https://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details. [plugin externalize-deps]

../node_modules/vite/node_modules/esbuild/lib/main.js:1225:27:
1225 │ let result = await callback({
╵ ^
Vitest config
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineWorkersConfig({
plugins: [tsconfigPaths()],
test: {
poolOptions: {
workers: {
wrangler: { configPath: "./wrangler.toml" },
main: "./src/index.ts",
},
},
},
});
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineWorkersConfig({
plugins: [tsconfigPaths()],
test: {
poolOptions: {
workers: {
wrangler: { configPath: "./wrangler.toml" },
main: "./src/index.ts",
},
},
},
});
Wrangler.toml
name = "worldjourney-api"
compatibility_date = "2023-12-01"
main = "./src/index.ts"
compatibility_flags = [ "nodejs_compat" ]

[[kv_namespaces]]
binding = "TOKENS"
id = "<>"
preview_id = "<>"

[env.production]
route = "api.worldjourney.app"

[env.staging]
route = "staging.api.worldjourney.app"
name = "worldjourney-api"
compatibility_date = "2023-12-01"
main = "./src/index.ts"
compatibility_flags = [ "nodejs_compat" ]

[[kv_namespaces]]
binding = "TOKENS"
id = "<>"
preview_id = "<>"

[env.production]
route = "api.worldjourney.app"

[env.staging]
route = "staging.api.worldjourney.app"
1 Reply
Jacob
JacobOP4mo ago
I forgot to specify type: "module" in package.json
Want results from more Discord servers?
Add your server