nuxt / test-utils

πŸ§ͺ Test utilities for Nuxt
http://nuxt.com/docs/getting-started/testing
MIT License
323 stars 84 forks source link

Following documentation and using `defineVitestConfig` results in an `[ERROR] "@nuxt/test-utils/config" resolved to an ESM file.` #704

Open ColtHands opened 10 months ago

ColtHands commented 10 months ago

Environment

Local machine

Stackblitz env

Reproduction

Repro stack blitz - https://stackblitz.com/edit/stackblitz-starters-cetpk5?file=vitest.config.js

Describe the bug

When following testing documentation - https://nuxt.com/docs/getting-started/testing, after adding vitest.config.{ts,js} with defineVitestConfig and a basic test, vitest run fails with an error

Bash error. ✘ [ERROR] "@nuxt/test-utils/config" 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/dist/node/chunks/dep-V3BH7oO1.js:68381:9: 68381 β”‚ } β•΅ ^ at bundleConfigFile/setup/< (/home/projects/stackblitz-starters-cetpk5/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:68381:35) at handlePlugins/requestCallbacks["on-resolve"] (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:1364:28) at handleRequest (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:722:17) at handleIncomingPacket (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:747:20) at readFromStdout (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:670:27) at EventEmitter.prototype.emit (node:events:42:9202) at addChunk (node:internal/streams/readable:105:4109) at readableAddChunk (node:internal/streams/readable:105:3816) at Readable.prototype.push (node:internal/streams/readable:105:2679) at onStreamRead (node:internal/stream_base_commons:158:2341) at _0x340f71/< (https://stackblitzstarterscetpk5-klbu.w-corp.staticblitz.com/blitz.f7aa08df.js:350:318835) at _0x241289 (https://stackblitzstarterscetpk5-klbu.w-corp.staticblitz.com/blitz.f7aa08df.js:350:320540) at _0x124cfc (https://stackblitzstarterscetpk5-klbu.w-corp.staticblitz.com/blitz.f7aa08df.js:350:317167) at _0x574284/

If there's something im doing wrong (eg Node version, some extra setup) this should be stated in the docs

Additional context

Sry if dupe, couldn't find a similar issue

Logs

No response

danielroe commented 10 months ago

This isn't Nuxt specific here, but to import @nuxt/test-utils in your vitest config, you either need to have to have type: "module" specified in your package.json or name it vitest.config.m{ts,js}.

We should make this clear in the docs.

cory-baker commented 9 months ago

getting the same thing but renaming to .cts did not work CleanShot 2024-02-27 at 10 17 59

cory-baker commented 9 months ago

update: renaming to .mts did work

danielroe commented 7 months ago

do you not have type: module in your package.json?

https://github.com/nuxt/starter/blob/v3/package.json#L4