#Api folder problem
197 messages · Page 1 of 1 (latest)
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
@eternal loom continuing from #general does the behavior/error change at all after adding the adapter?
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?
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
i will try to make it work by following your tips, i am new to astro, i have used nextjs for years and the api folder used to work without any problem, facing this issue for the first time now on astro.
i really appreciate you, i will give u an update tomorrow when i test it out
Can you try putting export const prerender = false in Salesforce.ts below the import statements?
i tried it did not work
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
💀
@strong pivot
Does the /api/salesforce form submission work locally when running astro dev?
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.
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.
and deployed it on vercel?
Yeah.
wow
u used latest astro version?
or astro version doesnt matter?
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.
yes the salesforce api is a bit complicated thats why i created the feedback.ts
this returns success as u can see when i submit the form
and it does not return success in vercel
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!');
do i include? export const prerender = false
If that works, then you know the route is OK. And you can add stuff back gradually to see when it breaks again.
Yes!
ok i will try it now
bruh
i even ran npm run build before pushing to github to be sure
OK, so it’s definitely some bigger issue with the project. Very weird.
so what do u think i should do?
Do you have any other prerender = false routes in the project? Or just this one?
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
i tried uninstalling and i got this after submitting the form:
am not sure if this will help but here is my project structure:, the index is empty
Not, it’s a Vercel bundling issue. It’s trying to load a dist/server/entry.mjs file which doesn’t exist in the build output. I don’t know enough about Vercel to be sure what the expected format is.
the index highlighted is empty
If you run astro build locally what does the .vercel/ directory it generates look like?
so the question here is how did urs did not break?
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.
Could you show the .vercel/ directory in file tree?
Does functions/_render.func/dist/ contain server/entry/mjs?
OK. So at least locally it seems the build is OK.
yes 😭
That means presumably Vercel is doing something weird in their build pipeline that breaks it.
But I really have no clue what 😅
💔
i will try to start a new project and build a simple api and check if it works with vercel
Yeah that would be great. Thank you!
no i should thank you for your time man
And if it still breaks definitely open an issue on GitHub.
bro i need to contact astro myself
🤣🤣🤣🤣🤣
@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
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!
We love to keep the web weird, but... not that weird.
Please open an issue on the withastro/adapters repo.
ok vercel is not working now, which hosting platform are u using chris?
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.)
bro i wish you good luck next time you use vercel with astro
i cant believe such a simple task cannot be done
could it be something to do with your static output? https://docs.astro.build/en/guides/endpoints/#request
built in static mode you only have access to
request.url
haven't read the full exchange between you and chris yet
ah I see the ssr flags mentioned above, should have read first lol
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.
I'm honestly kind of surprised how much I see output: "static"
in v5 I just leave it unset for the default hybrid mode 🤷♂️
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.
Fair point!
oh i did not know that, good to know
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
I can maybe spin one up at some point
free time is hard to come by these days lol
yeah i understand, but i have to thank you and chris for your time. I really appreciate you guys. I am glad people like you are in the community
😎 ❤️
@strong pivot when did vercel stop wanting the ./serverless export and choose to use default export?
could that be the issue here?
I think that change happened quite a while ago now?
huh, goes to show how long its been since i've hosted on any platform other than Coolify 😅
I just created a repo. Will deploy to Vercel in just a moment.
yeah please let me know my brother
Thank you
https://vercel-api-testing.vercel.app/
Seems to work just fine for me. Copy/pasted from the docs. Even added Preact,React,Solid,Vue,Svelte for the hell of it.
Contribute to hkbertoson/vercel-api-testing development by creating an account on GitHub.
Lol even put type email on the forms 😛
Nice!
huh?
then what did i do wrong?
this is my repo
did u modify any vercel build and development options
can you try and remove output: "static" from your astro config?
that is one difference I see
yeah i noticed also
so when i remove static it goes to hybrid by default yeah?
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 😅
i will try removing the static tomorrow and i will update you all
yeah?
aha
Ohhhhhhhh
Still don’t get why it would work locally though
look i will just use uppercase and remove the static
EXACTLY
i am just hoping i wake up and it works after the changes
i never spent this long solving a silly problem like that
@plush jungle @strong pivot @molten patio your boy made it
u know what was the issue?
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
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.
yeah bro its sad how when u do npm run build, and the .vercel folder is created, it doesnt automatically put it in the git ignore
bro i should thank you for your amazing feedback brother
I’ll also leave a note on your issue explaining we solved it 
@molten patio @strong pivot @plush jungle Thank you my brothers
yes please and thank u again
i hope you all have an amazing day
You as well!