#Nuxt Tests not working. Cannot find package '#imports'

4 messages · Page 1 of 1 (latest)

native sorrelBOT
#

Hi @supple vector. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, I can offer some guidance on your issue with setting up tests in a Nuxt application. The error you're encountering suggests there might be a problem with the test environment configuration or the way the tests are being run.

Here are a few steps you can try to resolve this issue:

  1. Ensure you have the correct dependencies installed. As mentioned in the Nuxt Testing documentation, you should install the following:

    npm i --save-dev @nuxt/test-utils vitest @vue/test-utils happy-dom playwright-core
    
  2. Make sure you have set up your vitest.config.ts file correctly. It should look something like this:

    import { defineVitestConfig } from '@nuxt/test-utils/config'
    
    export default defineVitestConfig({
      // any custom Vitest config you require
    })
    
  3. Check that you have added @nuxt/test-utils/module to your nuxt.config file:

    export default defineNuxtConfig({
      modules: [
        '@nuxt/test-utils/module'
      ]
    })
    
  4. Ensure you're using the Nuxt environment for your tests. You can do this by either:

    • Adding .nuxt. to your test file names (e.g., my-file.nuxt.test.ts)
    • Adding // @vitest-environment nuxt as a comment at the top of your test files
    • Setting environment: 'nuxt' in your Vitest configuration
  5. If you're still encountering issues, you might need to check your package.json file. As mentioned in the Nuxt Testing documentation, you should have "type": "module" specified in your package.json, or rename your vitest config file to vitest.config.m{ts,js}.

#

If these steps don't resolve your issue, it's possible that there might be a compatibility issue between the versions of Nuxt and @nuxt/test-utils you're using. In that case, you might want to check for any recent updates to these packages or consider opening an issue on the Nuxt GitHub repository.

Remember, the Nuxt testing environment is primarily designed for client-side testing. If you're trying to test server-side code or Nitro endpoints, you might encounter additional challenges as full server environment support is still in development.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@supple vector Kapa.ai is still learning and improving, please let me know how I did by reacting below.