How to deploy the backend (hono) server on vercel? #21
-
When trying to deploy to Vercel it's building normally ![]() But getting this type error after build ![]() Tried a lot of different ways but nothing works. References |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
hmm - the demo site (https://rtstack.nktnet.uk) only deploy the Web Frontend to vercel. The backend server in the demo site uses Docker deployment to fly.io. Regardless, I can reproduce this locally using ![]() It appears that To hackily patch the type errors with click to viewdiff --git a/apps/server/src/index.ts b/apps/server/src/index.ts
index 725fd4c..afd9d37 100644
--- a/apps/server/src/index.ts
+++ b/apps/server/src/index.ts
@@ -74,7 +74,7 @@ app.use(
async (c, next) => {
const { matched, response } = await api.handler(c.req.raw);
if (matched) {
- return c.newResponse(response.body, response);
+ return c.newResponse((response as any).body, response);
}
await next();
diff --git a/packages/api/src/server/index.ts b/packages/api/src/server/index.ts
index 51c42b7..c65bf3d 100644
--- a/packages/api/src/server/index.ts
+++ b/packages/api/src/server/index.ts
@@ -68,7 +68,7 @@ export const createApi = ({
context: await createORPCContext({
db,
auth,
- headers: request.headers,
+ headers: (request as any).headers,
}),
});
},
diff --git a/packages/db/src/schemas/posts.ts b/packages/db/src/schemas/posts.ts
index 139baa6..cb9e3f4 100644
--- a/packages/db/src/schemas/posts.ts
+++ b/packages/db/src/schemas/posts.ts
@@ -5,8 +5,8 @@ import { user } from './auth';
export const post = pgTable('post', (t) => ({
id: t.uuid().primaryKey().defaultRandom(),
- title: t.varchar({ length: 256 }).notNull(),
- content: t.text().notNull(),
+ title: t.varchar({ length: 256 }).notNull() as any,
+ content: t.text().notNull() as any,
createdAt: t
.timestamp({ mode: 'string', withTimezone: true })
.notNull()
@@ -22,5 +22,5 @@ export const CreatePostSchema = v.omit(
title: v.pipe(v.string(), v.minLength(3), v.maxLength(256)),
content: v.pipe(v.string(), v.minLength(5), v.maxLength(512)),
}),
- ['id', 'createdAt', 'createdBy'],
+ ['id', 'createdAt', 'createdBy'] as any,
); This will allow Naturally, you will get many runtime errors when deploying and running in production, but hopefully that helps with further investigation into the issue. I've also reported this to vercel: |
Beta Was this translation helpful? Give feedback.
Workaround Overview
Use Vercel Primitives in combination with prebuilt deployment.
This means we will be building the backend server application outside of Vercel (e.g. on your local machine or using GitHub Actions/another CI tool), rather than linking a git repository directly to the Vercel project.
A potential benefit is that only the transpiled code is sent to Vercel instead of the full source code.
I've added an example of the vercel-server-deploy branch - most of the logic is encapsulated in the ./deploy-vercel-server.sh shell script.
Other changes are:
PUBLIC_SERVER_URL
will fallback toVERCEL_URL
tsdown
, use the entry pointsrc/index.ts
(the exported…