Open ColtHands opened 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.
getting the same thing but renaming to .cts
did not work
update: renaming to .mts
did work
do you not have type: module
in your package.json?
Environment
Local machine
Build Modules: -
Stackblitz env
Build Modules: -
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}
withdefineVitestConfig
and a basic test,vitest run
fails with an errorBash 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/< (https://stackblitzstarterscetpk5-klbu.w-corp.staticblitz.com/blitz.f7aa08df.js:350:319772) at _0x574284/< (https://stackblitzstarterscetpk5-klbu.w-corp.staticblitz.com/blitz.f7aa08df.js:350:319750) at _0x574284 (https://stackblitzstarterscetpk5-klbu.w-corp.staticblitz.com/blitz.f7aa08df.js:350:319784) This error came from the "onResolve" callback registered here: node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:68345:26: 68345 β name: 'inject-file-scope-variables', β΅ ^ at setup (/home/projects/stackblitz-starters-cetpk5/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:68345:27) at handlePlugins (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:1283:26) at buildOrContextImpl (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:969:18) at buildOrContext (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:778:23) at build/< (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:2020:15) at build (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:2019:25) at build (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:1853:51) at bundleConfigFile (/home/projects/stackblitz-starters-cetpk5/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:68306:35) at loadConfigFromFile (/home/projects/stackblitz-starters-cetpk5/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:68282:31) at resolveConfig (/home/projects/stackblitz-starters-cetpk5/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:67884:34) at _createServer (/home/projects/stackblitz-starters-cetpk5/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:60373:26) at createServer (/home/projects/stackblitz-starters-cetpk5/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:60370:12) at createViteServer (/home/projects/stackblitz-starters-cetpk5/node_modules/vitest/dist/vendor/node.xyYo9ZvH.js:7672:30) at createVitest (/home/projects/stackblitz-starters-cetpk5/node_modules/vitest/dist/vendor/node.xyYo9ZvH.js:8894:24) The plugin "externalize-deps" was triggered by this import vitest.config.js:4:35: 4 β import { defineVitestConfig } from '@nuxt/test-utils/config' β΅ ~~~~~~~~~~~~~~~~~~~~~~~~~ failed to load config from /home/projects/stackblitz-starters-cetpk5/vitest.config.js β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β― Unhandled Error β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β―β― Error: Build failed with 1 error: node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:68381:9: ERROR: [plugin: externalize-deps] "@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. at failureErrorWithLog (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:1641:15) at buildResponseToResult/< (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:1049:44) at runOnEndCallbacks (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:1476:49) at buildResponseToResult (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:1047:24) at buildOrContextContinue/< (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:1076:16) at sendRequest/responseCallbacks[id] (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:694:17) at handleIncomingPacket (/home/projects/stackblitz-starters-cetpk5/node_modules/esbuild/lib/main.js:754:17) 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/< (https://stackblitzstarterscetpk5-klbu.w-corp.staticblitz.com/blitz.f7aa08df.js:350:319772) at _0x574284/< (https://stackblitzstarterscetpk5-klbu.w-corp.staticblitz.com/blitz.f7aa08df.js:350:319750) at _0x574284 (https://stackblitzstarterscetpk5-klbu.w-corp.staticblitz.com/blitz.f7aa08df.js:350:319784) { errors: [Getter/Setter], warnings: [Getter/Setter] }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