tim
How to test Nuxt 3 Nitro Server endpoints and middlewares (avoiding defineEventHandler not defined)
Hi, how would you test a Nuxt server api endpoint or middleware? I do struggle with
ReferenceError: defineEventHandler is not defined
errors. defineEventHandler
is a Nitro-specific runtime utility that is not available in my test environment. The way my test is currently set up, I am trying to execute the middleware file directly, but defineEventHandler
is not properly mocked. How could I do that? I haven't found any working online resources for examples of testing Nuxt server routes / Nitro routes with Vitest in a Nuxt project :/
Would be very happy if anyone could look into my setup or provide me with resources so that I can get my setup to work
10 replies
Nuxt 3.12.1 Update: Prerender Error with app.use Function
Hello everyone! I've recently encountered an issue after updating to Nuxt version 3.12.1. My deployment to Cloudflare Pages fails during the prerendering process with a
SyntaxError: Need to install with \
app.use function
error. This problem did not occur in the previous version (3.11.2), and it only affects the Pull Request Preview Deployment. Here's mynpx nuxi info
for reference:
- Operating System: Windows_NT
- Node Version: v20.8.1
- Nuxt Version: 3.12.1
- CLI Version: 3.12.0
- Nitro Version: 2.9.6
- Package Manager: [email protected]
- User Config: preset, experimental, devtools, modules, serverMiddleware, supabase, i18n, cloudflareAnalytics, turnstile, css, postcss, app, runtimeConfig, routeRules, image, security, content, typescript
- Runtime Modules: @nuxt/[email protected], @nuxt/[email protected], @nuxt/[email protected], @nuxtjs/[email protected], @nuxtjs/[email protected], @nuxtjs/[email protected], @nuxtjs/[email protected], @nuxthq/[email protected], [email protected], [email protected], [email protected], [email protected]
Has anyone else experienced this issue, or does anyone have insights on what might be causing this and how to resolve it? Any help would be greatly appreciated!
Locally when entering the dev mode, the logs have shown different errors on different starts. At first it was the i18n module which seems to create the problem but now its Supabase and due to my usage of Cloudflare Pages and my tests I am really sure that it is because of the upgrade. When I downgrade back everything seems to work fine. Has something changed for configuring the Nuxt Configuration file (nuxt.config.ts
)?9 replies