N
Nuxt5w ago
luhu

"#build/nuxt.config.mjs" is not defined

Hi, I'm trying to migrate away from auto imports and after fixing every import after disabling it in the nuxt config, I can't run the unit tests anymore. They do complain about Package import specifier "#build/nuxt.config.mjs" is not defined in package /node_modules/nuxt/package.json imported from /node_modules/nuxt/dist/app/nuxt.js. I've tried mocking the file or adding it as an alias in the vitest config but it's not working. Any idea on how to fix it?
2 Replies
kapa.ai
kapa.ai5w ago
Hi @luhu. 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 knowledge sources provided, I can offer some insights into your issue with disabling auto imports in Nuxt and the subsequent problems with unit testing. However, the information available doesn't provide a direct solution to your specific error. Let me explain what we can gather from the available information: 1. Auto Imports in Nuxt: Nuxt 3 uses auto imports for components, composables, and utilities. Disabling these can indeed cause issues, as you've experienced. The Nuxt 3: Auto Imports in Vue and Nuxt - The Good and the Bad video discusses some of the pros and cons of auto imports. 2. Disabling Auto Imports: According to the Github Issue about adding a feature toggle to disable autoImports, there isn't a straightforward way to disable all auto imports in Nuxt 3. The settings to disable auto-imports of components exist, but there are no settings to disable other auto-imports like Vue re-exports, @unhead/vue re-exports, or project-specific composables and utils folder re-exports. 3. Unit Testing in Nuxt: For unit testing in Nuxt, the recommended approach is to use @nuxt/test-utils. The Nuxt documentation on Unit Testing provides information on setting up the testing environment. However, it doesn't address the specific issue you're facing with "#build/nuxt.config.mjs". 4. Mocking Imports: The Nuxt documentation on mocking imports suggests using mockNuxtImport for mocking Nuxt's auto import functionality. However, this is typically used for mocking specific imports rather than resolving issues with the nuxt.config file. Given the error you're encountering, it seems that the testing environment is unable to resolve the "#build/nuxt.config.mjs" import. This could be due to the way Nuxt handles its internal imports and how they're resolved in the testing environment. Unfortunately, the provided knowledge sources don't contain a direct solution to your specific error. It might be worth considering the following steps: 1. Ensure you're using the latest version of Nuxt and @nuxt/test-utils. 2. Check if there are any recent issues or discussions in the Nuxt GitHub repository about similar problems. 3. Consider reaching out to the Nuxt community or opening an issue on the Nuxt GitHub repository, as this seems to be a specific problem that might require attention from the Nuxt team. I apologize that I couldn't provide a more concrete solution to your problem. The issue you're facing seems to be quite specific and might require more in-depth investigation or support from the Nuxt development team. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5w ago
<@894863266709385237> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?