-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Vercel Edge with Nuxt #180
Comments
Hey @cosbgn, it should be supported. Which package from storage are you using? kv, blob, postgres? Do provide more details (basically how you are using it) and we can help you out. Thanks |
Hi @vvo This is a small reproduction: https://github.com/cosbgn/edgenu/blob/1e752299099692d875f2bec97edf4ca1c9cc7bdb/server/utils/utils.js use this version as I've tested all sort of libraries to get it to work |
I've made a new branch for vercel/storage: |
I have been fighting this issue for several days now and would love to understand what the next step is or if there is any kind of workaround. I am using nuxt (created from vercel's provided template). Things I have tried:
In most cases I am able to connect via localhost and run a simple query but when I deploy to Vercel I hit the error mentioned in the initial post here. In the current state I am handling the Code is very simple.
import { createPool } from '@vercel/postgres';
const postgresUrl = useRuntimeConfig().POSTGRES_URL;
const pool = createPool({
connectionString: postgresUrl,
});
export default defineEventHandler(async (event) => {
const users = await pool.sql`SELECT * FROM users;`;
return {
users: users.rows,
};
}); Any ideas would be greatly appreciated. There is a group of us who are all really excited about vercel and getting this to work. |
@cpmooney can you tell us which version of |
Looks like it's the latest version: 0.4.0 |
@cpmooney I am unable to reproduce your issue unfortunately. I'm on import { createPool, sql } from "@vercel/postgres";
import { NextResponse } from "next/server";
const pool = createPool({
connectionString: process.env.POSTGRES_URL,
});
export const runtime = "edge";
export async function GET() {
const { rows: sqlDirect } = await sql`SELECT 1 as foobar`;
const { rows: sqlPool } = await pool.sql`SELECT 1 as foobar`;
return NextResponse.json({
sqlDirect,
sqlPool,
});
} And the result I get hitting the endpoint: $ http https://vercel-storage-playground.vercel.app/api/vercel-storage-issue-180
HTTP/1.1 200 OK
Cache-Control: public, max-age=0, must-revalidate
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Wed, 28 Jun 2023 08:55:47 GMT
Server: Vercel
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
Transfer-Encoding: chunked
X-Matched-Path: /api/vercel-storage-issue-180
X-Vercel-Cache: MISS
X-Vercel-Id: lhr1::s7ftl-1687942546989-a1bb1e2c5125
{
"sqlDirect": [
{
"foobar": 1
}
],
"sqlPool": [
{
"foobar": 1
}
]
} And to confirm the function is an edge function: Can you create an exact reproduction for me to deploy on Vercel? |
Hi, @adriancooney I spun up a new repo from scratch (from vercel's template) and am hitting the same error. Here is the repo: https://github.com/cpmooney/nuxt-vercel-example here is the deployment to vercel: https://nuxt-vercel-example-1pkfkfbyd-cpmooney.vercel.app/ My neon database just has a single table called but if you click on the link above to see what is deployed, you will see the error. Error in the vercel log is always the same:
Environment variable Just to confirm that the neon connection is what's causing the issue, here is the deployment for a commit I pushed which does not include the postgres connection. Here is the commit + deployment in case it's helpful to compare: https://github.com/cpmooney/nuxt-vercel-example/commit/df0d06f70ef486b9f92434793a694ac92e48c59f Let me know if you have any ideas or if this issue belongs elsewhere. I would love to understand what's going on. Thanks!
|
After digging around a little more I have come to the conclusion that this is just not compatible with nuxt. |
Also my reproductions at the beginning on this issue are still not working with the same error |
So it looks like this is a bug with Nuxt and Nitro, Nuxt's build system. The In the meantime, I've found a workaround using the +import { resolve } from "path";
export default defineNuxtConfig({
nitro: {
preset: "vercel-edge",
},
+ alias: {
+ "@vercel/postgres": resolve(
+ __dirname,
+ "./node_modules/@vercel/postgres/dist/index.js"
+ ),
+ },
runtimeConfig: {
POSTGRES_URL: process.env.POSTGRES_URL,
},
}); We force Nuxt to resolve the Edge compatible entrypoint for Given that this is a bug in Nuxt/Nitro, I'm going to close this issue out. Folks can use the workaround above or wait for the issue to be fixed in Nitro and upgrade their package - there's not much we can do from this side of the house. Thanks for the report @cosbgn and @cpmooney. |
Thanks for the write-up @adriancooney, this is exactly the case. This is a tricky issue to tackle, because there's no convention about the exports naming resolution. In the future feel free to ping me or to open an issue in Nuxt/Nitro so we can propose a solution quicker. |
Currently I think the
edge
runtime is not supported, right?The text was updated successfully, but these errors were encountered: