nuxt / nuxt/test-utils

Error when loading browser-entry.mjs: Syntax error, "qs" does not provide an export named "default"

Open
#1,388 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
Dominant language
TypeScript
Stars
437
Forks
120
Avg merge
22h 52m
Merged PRs (30d)
23

Description

Environment
  • Operating System: Linux
  • Node Version: v20.19.4
  • Nuxt Version: 3.18.1
  • CLI Version: 3.27.0
  • Nitro Version: 2.12.4
  • Package Manager: yarn@4.2.2
  • Builder: -
  • User Config: devtools, modules, ui, colorMode, css, formkit, pinia, components, ssr, typo3
  • Runtime Modules: @nuxt/ui@3.3.0, @pinia/nuxt@0.11.2, @t3headless/nuxt-typo3@2.2.1, @formkit/nuxt@1.6.9, @nuxtjs/storybook@9.0.0, @nuxt/test-utils/module@3.19.2, nuxt-viewport@2.3.1
  • Build Modules: -
Reproduction

See https://github.com/andreaswolf/nuxt-issue-repro

Run yarn run vitest --project=e2e for a working test, yarn run vitest --project=e2e-nuxt will not work.

Describe the bug

Tests run fine without Nuxt/defineVitestProject. As soon as I use defineVitestProject(), there are two errors and the tests are not run anymore:

  1. Error: Failed to import test file /home/aw/Kunden/fes/fes-cp-v11/frontend-v2/node_modules/@nuxt/test-utils/dist/runtime/browser-entry.mjs
    Caused by: SyntaxError: The requested module '/node_modules/qs/lib/index.js?v=c5ced9fb' does not provide an export named 'default'

  2. TypeError: Cannot set properties of undefined (setting 'PROD')

The second issue (very likely) comes from setupEnv in vitest's setup-common.js. I can also open a separate issue for this.

Additional context

No response

Logs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the failing yarn run vitest --project=e2e-nuxt reproduction and inspect @nuxt/test-utils/dist/runtime/browser-entry.mjs, focusing on its import of qs. Compare it with the working e2e project, then review Vitest's setup-common.js separately for the PROD error. Done means the Nuxt project tests run without either reported failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, nuxt, typescript
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.