#Api folder problem

197 messages · Page 1 of 1 (latest)

eternal loom
#

Trying to use api Post request in vercel but getting errors:
, and astro.config, and api, please help

#

i tried npm run build, tried removing all node mdules and reinstalling

#

please help if u can

#

api folder only working locally but not working on vercel link

plush jungle
#

@eternal loom continuing from #general does the behavior/error change at all after adding the adapter?

eternal loom
# plush jungle <@676890950303481897> continuing from <#830184175176122389> does the behavior/er...
import { defineConfig } from 'astro/config'
import vercel from '@astrojs/vercel'
import tailwind from '@astrojs/tailwind'
import { imageService } from '@unpic/astro/service'
import partytown from '@astrojs/partytown'
// import qwikdev from '@qwikdev/astro'
import react from '@astrojs/react'
import sitemap from '@astrojs/sitemap'

export default defineConfig({
  output: 'static',
  images: {
    service: imageService({
      placeholder: 'blurhash',
    }),
  },
  site: 'https://saasproperties-astro.vercel.app',
  integrations: [
    tailwind(),
    // qwikdev(),
    react(),
    partytown({
      // Example: Add dataLayer.push as a forwarding-event
      config: {
        forward: ['dataLayer.push'],
      },
    }),
    sitemap(),
  ],
  adapter: vercel(),
})
#

this is my config

#

api:

#

i am even using export const prerender = false

#

but still getting error 500 when i try to do a post request

#

here is how i do the post:

#

am i missing something?

plush jungle
#

Hard to say, I’m on my phone atm

You could add in some console logs to try and determine where and why the form is failing

Also I think your content type and body are not helping. Why not remove the content type and just send the actual formData instead of converting it to a string?

Helping eliminate some of this complexity and unnessescary data manipulation might help (unnecessary from my perspective, obviously I don’t have the full context)

#

Also make sure to check the network tab in your browser dev tools to look for more info

eternal loom
#

i really appreciate you, i will give u an update tomorrow when i test it out

ornate pagoda
#

Can you try putting export const prerender = false in Salesforce.ts below the import statements?

eternal loom
#

i even copied the exact code:

#

here

#

copied it word by word

#

depolyed it on vercel

#

getting same error

#

code is from astro docs and getting error, i dont know how

#

did astro miss a step?

#

form is very simple:

#

as u can see its in the api folder and u just get a json returned to u

#

it works locally but not in vercel

#

config:

#

at this point u cannot convince me that api folder works with vercel adapter

#

💀

eternal loom
#

@strong pivot

strong pivot
#

Does the /api/salesforce form submission work locally when running astro dev?

eternal loom
#

yes it does

#

this simple form shows success when i submit

#

it doesnt on vercel

strong pivot
#

Thanks. It seems to be some kind of bundling issue because the error you shared from the Vercel logs is failing to load a module somehow.

eternal loom
#

did u ever face an issue liek this?

#

when using api

#

folder

strong pivot
#

I don’t think it’s related to the folder specifically. I’ve definitely deployed sites with dynamic /api/ routes.

#

It’s probably some specific combination of code or dependencies.

strong pivot
#

Yeah.

eternal loom
#

wow

eternal loom
#

or astro version doesnt matter?

strong pivot
#

My guess based on what I’ve seen here so far might be that the crypto-js dependency is getting in the way? But it’s quite hard to debug.

eternal loom
#

this returns success as u can see when i submit the form

#

and it does not return success in vercel

strong pivot
#

What I might suggest is to try deploying an /api/salesforce route that doesn’t really do anything just:

export const POST = () => new Response('It works!');
eternal loom
strong pivot
#

If that works, then you know the route is OK. And you can add stuff back gradually to see when it breaks again.

strong pivot
eternal loom
#

ok i will try it now

#

bruh

#

i even ran npm run build before pushing to github to be sure

strong pivot
#

OK, so it’s definitely some bigger issue with the project. Very weird.

eternal loom
#

so what do u think i should do?

strong pivot
#

Do you have any other prerender = false routes in the project? Or just this one?

eternal loom
#

only this

#

everything is static

#

its only the apis

#

these two are the only two files with prerender = false

#

is this happened because of the redirects?

#

cause i redirect from '/' to '/en/' at the start

eternal loom
#

am not sure if this will help but here is my project structure:, the index is empty

strong pivot
eternal loom
#

the index highlighted is empty

strong pivot
#

If you run astro build locally what does the .vercel/ directory it generates look like?

eternal loom
strong pivot
#

Yeah, like I said, it’s probably something specific in your project, either some code, or some dependencies or some combination of factors, I’m not really sure.

eternal loom
#

when i run astro build

strong pivot
#

Could you show the .vercel/ directory in file tree?

eternal loom
strong pivot
#

Does functions/_render.func/dist/ contain server/entry/mjs?

eternal loom
#

yes

strong pivot
#

OK. So at least locally it seems the build is OK.

eternal loom
#

yes 😭

strong pivot
#

That means presumably Vercel is doing something weird in their build pipeline that breaks it.

#

But I really have no clue what 😅

eternal loom
#

💔

#

i will try to start a new project and build a simple api and check if it works with vercel

strong pivot
#

Yeah that would be great. Thank you!

eternal loom
#

no i should thank you for your time man

strong pivot
#

And if it still breaks definitely open an issue on GitHub.

eternal loom
#

🤣🤣🤣🤣🤣

strong pivot
eternal loom
#

@strong pivot

#

yo chris

#

brand new project

#

and still error 💀💀💀💀💀

#

can u tell me your api worked on which astro version?

#

so i can install the same version and try

strong pivot
#

Hmm, it was a little while ago. Given you managed to reproduce with the latest versions, I think an issue is the way to go!

next coralBOT
#

We love to keep the web weird, but... not that weird.

Please open an issue on the withastro/adapters repo.

eternal loom
#

ok sure

#

thank you

eternal loom
strong pivot
#

Oh boy. Not a good day for Vercel 😄

#

I usually use Netlify, but also use Vercel for some stuff. (Or GitHub Pages for fully static things like docs for projects.)

eternal loom
#

i cant believe such a simple task cannot be done

plush jungle
#

ah I see the ssr flags mentioned above, should have read first lol

strong pivot
#

Yeah, those docs are maybe a bit outdated. These days output: 'static' can also ship some SSR code if you have an adapter and are using prerender = false in some places.

plush jungle
#

I'm honestly kind of surprised how much I see output: "static"

in v5 I just leave it unset for the default hybrid mode 🤷‍♂️

strong pivot
#

I guess if you’ve switched to server at some point, it’s one way to switch back. Depends a bit what you’ve been doing.

plush jungle
#

Fair point!

eternal loom
#

but i am suprised i am the only person complaining about this, can someone in their free time just create an astro app and make a post api that will send a request with a message and dep,loy on vercel?

#

it will not take long i am just very curious if its only me

plush jungle
#

I can maybe spin one up at some point

free time is hard to come by these days lol

eternal loom
#

😎 ❤️

rare junco
#

@strong pivot when did vercel stop wanting the ./serverless export and choose to use default export?

#

could that be the issue here?

strong pivot
#

I think that change happened quite a while ago now?

rare junco
molten patio
eternal loom
molten patio
plush jungle
#

Lol even put type email on the forms 😛

strong pivot
#

Nice!

eternal loom
#

then what did i do wrong?

#

this is my repo

#

did u modify any vercel build and development options

plush jungle
#

can you try and remove output: "static" from your astro config?

#

that is one difference I see

eternal loom
#

so when i remove static it goes to hybrid by default yeah?

plush jungle
#

Correct

#

Which is still static

#

unless you opt in to prerendering with the export

#

But given your no server entry error, perhaps hard setting it to static is causing issues with the adapter or somesuch

#

just spitballing 😅

eternal loom
#

i will try removing the static tomorrow and i will update you all

plush jungle
#

Oh you know what

#

your post is in lowercase

eternal loom
#

yeah?

plush jungle
eternal loom
#

aha

strong pivot
#

Ohhhhhhhh

eternal loom
#

i tried it with uppercase before thats why i switched to lowercase

#

🤣🤣🤣🤣

strong pivot
#

Still don’t get why it would work locally though

eternal loom
#

look i will just use uppercase and remove the static

eternal loom
eternal loom
#

i never spent this long solving a silly problem like that

eternal loom
#

@plush jungle @strong pivot @molten patio your boy made it

eternal loom
#

i compard @molten patio 's repo and mine, i noticed he had .vercel folder in his gitignore

#

.verel folder cause problems with my deployment

#

that was the problem

strong pivot
#

Ohhhh, yeah that shouldn’t be committed. But I also didn’t spot it. Glad to get it figured out!!

#

And thanks for sharing — helps us know something more to look out for if we ever have to debug a similar issue.

eternal loom
eternal loom
strong pivot
#

I’ll also leave a note on your issue explaining we solved it houston_salute

eternal loom
#

@molten patio @strong pivot @plush jungle Thank you my brothers

eternal loom
#

i hope you all have an amazing day

molten patio
#

You as well!