unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.89k stars 496 forks source link

defineLazyEventHandler is not defined #2636

Closed martinszeltins closed 2 months ago

martinszeltins commented 2 months ago

Environment

Stackblitz, local = same results

Reproduction

https://stackblitz.com/~/github.com/martinszeltins/nuxt-from-scratch

Describe the bug

When I run the nitro dev command it shows me the following error. But h3 is installed and defineLazyEventHandler is supposed to be available. I have also extended nitro types in tsconfig and my IDE seems to recognize it as auto-import. I don't understand what is causing this problem.

> nitropack prepare

The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

 ERROR  defineLazyEventHandler is not defined                                                        1:19:55 PM

  at eval (nitro.config.ts#cjs:15:14)
  at evalModule (node_modules/.pnpm/jiti@1.21.6/node_modules/jiti/dist/jiti.js#cjs:1:247388)
  at Object.jiti (node_modules/.pnpm/jiti@1.21.6/node_modules/jiti/dist/jiti.js#cjs:1:245316)
  at resolveConfig (node_modules/.pnpm/c12@1.11.1/node_modules/c12/dist/shared/c12.cab0c9da.mjs:365:26)
  at async loadConfig (node_modules/.pnpm/c12@1.11.1/node_modules/c12/dist/shared/c12.cab0c9da.mjs:167:23)
  at async loadOptions (node_modules/.pnpm/nitropack@2.9.7/node_modules/nitropack/dist/nitro.mjs:4782:21)
  at async Module.createNitro (node_modules/.pnpm/nitropack@2.9.7/node_modules/nitropack/dist/nitro.mjs:5119:19)
  at async Object.run (node_modules/.pnpm/nitropack@2.9.7/node_modules/nitropack/dist/cli/prepare.mjs:84:19)
  at async runCommand (node_modules/.pnpm/citty@0.1.6/node_modules/citty/dist/index.mjs:337:16)
  at async runCommand (node_modules/.pnpm/citty@0.1.6/node_modules/citty/dist/index.mjs:328:11) 

 ERROR  defineLazyEventHandler is not defined                                                        1:19:55 PM

 ELIFECYCLE  Command failed with exit code 1.

Additional context

No response

Logs

No response

martinszeltins commented 2 months ago

nevermind, just had to import it from h3

import { defineEventHandler, defineLazyEventHandler, fromNodeMiddleware } from 'h3'