middleware icon indicating copy to clipboard operation
middleware copied to clipboard

Vercel Edge - Zod Openapi

Open draew6 opened this issue 2 years ago • 12 comments

Error: The Edge Function "api/index" is referencing unsupported modules: - @hono: hono/utils/url

this is what happens when i add openAPIHono to project. Does it mean swagger is not supported in edge runtime?

draew6 avatar Jan 01 '24 16:01 draew6

@draew6

We cannot know with that much information. Please share the minimal code or project to reproduce.

yusukebe avatar Jan 01 '24 23:01 yusukebe

@yusukebe

app.ts


import { swaggerUI } from '@hono/swagger-ui'
import { OpenAPIHono} from '@hono/zod-openapi'
import { Hono } from 'hono'

const app = new OpenAPIHono()
//const app = new Hono()


app.get("/balance", async (c) => {
    return c.json([])
  })

  app.get('/', swaggerUI({ url: '/doc'}))

export default app

api/index.ts

import { handle } from 'hono/vercel'
import app from '../app.js'

export const config = {
  runtime: 'edge'
}


export default handle(app)

vercel.json

{
  "rewrites": [
    {
      "source": "/(.*)",
      "destination": "/api"
    }
  ]
}

after trying to deploy with vercel command(CLI) its gives me

Error: The Edge Function "api/index" is referencing unsupported modules: - @hono: hono/utils/url It works with Hono instance or if I disable Edge

draew6 avatar Jan 02 '24 19:01 draew6

@draew6

Thanks. But, I can't reproduce the problem. The following project works well!

https://github.com/yusukebe/vercel-zod-openapi

yusukebe avatar Jan 02 '24 21:01 yusukebe

@yusukebe hmm weird, i just cloned and typed "vercel" image did you use "vercel" instead of "vercel dev" ? What else can I do to debug it? I am on vercel hobby if it matters

draew6 avatar Jan 02 '24 21:01 draew6

@draew6

AH, sorry! I only use vercel dev, but when I use vercel command to deploy, it fails.

Screenshot 2024-01-03 at 6 47 10

yusukebe avatar Jan 02 '24 21:01 yusukebe

This is certainly an error I've never seen before and don't know how to resolve. Hmm

yusukebe avatar Jan 02 '24 21:01 yusukebe

I am also getting the same issue here, along with the hono/jsx/jsx-runtime module.

I think the issue here is that Edge Functions (along with some other bundlers/runtimes) seem to struggle with resolving package.json#exports (at least nested modules – ie. hono/x/y).

A possible solution could be to create proxy packages (a package.json in a subdirectory that have resolvers to the dist files). Here is an example.

jxom avatar Feb 12 '24 09:02 jxom

Hello @draew6, Did you fix the problem with @jxom 's solution? Can you share your fix ?

kevinbalicot avatar Feb 13 '24 15:02 kevinbalicot

@jxom @kevinbalicot sorry, i am new to this. How would that look like in my example please?

draew6 avatar Feb 21 '24 22:02 draew6

I have the same error. Any updates on this?

nhtera avatar Jul 01 '24 17:07 nhtera

Same problem. Any updates?

akopachov avatar Oct 15 '24 11:10 akopachov