#Nuxt Tests not working. Cannot find package '#imports'
4 messages · Page 1 of 1 (latest)
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:
-
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 -
Make sure you have set up your
vitest.config.tsfile correctly. It should look something like this:import { defineVitestConfig } from '@nuxt/test-utils/config' export default defineVitestConfig({ // any custom Vitest config you require }) -
Check that you have added
@nuxt/test-utils/moduleto yournuxt.configfile:export default defineNuxtConfig({ modules: [ '@nuxt/test-utils/module' ] }) -
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 nuxtas a comment at the top of your test files - Setting
environment: 'nuxt'in your Vitest configuration
- Adding
-
If you're still encountering issues, you might need to check your
package.jsonfile. As mentioned in the Nuxt Testing documentation, you should have"type": "module"specified in yourpackage.json, or rename your vitest config file tovitest.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.