Closed simplenotezy closed 3 months ago
You have Vitest configs in your dist folder, compiled to CJS. Vitest is finding them and trying to use them, which leads to inadvertent require
of this plugin. I recommend adding dist
to your Vitest exclude patterns.
Closing as mistaken, since this is user error.
You have Vitest configs in your dist folder, compiled to CJS. Vitest is finding them and trying to use them, which leads to inadvertent
require
of this plugin. I recommend addingdist
to your Vitest exclude patterns.Closing as mistaken, since this is user error.
@aleclarson btw didnt help me
exclude: ['**/node_modules/**', '**/dist/**'],
✘ [ERROR] "vite-tsconfig-paths" resolved to an ESM file. ESM file cannot be loaded by `require`
@Git-I985 I just hit this too, solution for me was to set "type": "module"
in my package.json
@Git-I985 I just hit this too, solution for me was to set
"type": "module"
in mypackage.json
its a kinda major change for big old projects :))
Renaming my vitest.config.ts
to vitest.config.mts
fixed the error for me.
This solution was documented in https://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only (which is in the original error message).
I am trying to install the Vitest VSCode Extension in my NestJS project, but upon installation I see the following 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]
See full error log
``` [INFO 20:02:21] [v1.2.0] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace. [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.config.js) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (backend/vitest.e2e.config.mts) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (backend/vitest.config.mts) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.config.mjs) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.config.e2e.js) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.e2e.config.js) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.config.d.mts) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.e2e.config.d.mts) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.e2e.config.mjs) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.config.e2e.mjs) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.config.e2e.d.mts) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [INFO 20:02:21] [API] Running Vitest v2.0.5 (dist/vitest.test.config.js) with Node.js: /Users/mf/.nvm/versions/node/v20.11.0/bin/node [Worker] ✘ [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/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:1225:27: 1225 │ let result = await callback({ ╵ ^ at file:///Users/mf/Projects/kite/backend/node_modules/.pnpm/vite@5.4.1_@types+node@20.14.13_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-Cy9twKMn.js:66526:23 at requestCallbacks.on-resolve (/Users/mf/Projects/kite/backend/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:1225:28) at handleRequest (/Users/mf/Projects/kite/backend/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:647:17) at handleIncomingPacket (/Users/mf/Projects/kite/backend/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:672:7) at Socket.readFromStdout (/Users/mf/Projects/kite/backend/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:600:7) at Socket.emit (node:events:518:28) at addChunk (node:internal/streams/readable:559:12) at readableAddChunkPushByteMode (node:internal/streams/readable:510:3) at Readable.push (node:internal/streams/readable:390:5) at Pipe.onStreamRead (node:internal/stream_base_commons:190:23) This error came from the "onResolve" callback registered here: ../node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:1150:20: 1150 │ let promise = setup({ ╵ ^ at setup (file:///Users/mf/Projects/kite/backend/node_modules/.pnpm/vite@5.4.1_@types+node@20.14.13_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-Cy9twKMn.js:66488:18) at handlePlugins (/Users/mf/Projects/kite/backend/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:1150:21) at buildOrContextImpl (/Users/mf/Projects/kite/backend/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:873:5) at Object.buildOrContext (/Users/mf/Projects/kite/backend/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:699:5) at /Users/mf/Projects/kite/backend/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:2023:15 at new Promise (Any ideas what I am missing here? I use the .mts config file approach.