Skip to content
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

Error deploying latest version on Vercel #210

Open
jwoa opened this issue Nov 26, 2023 · 13 comments
Open

Error deploying latest version on Vercel #210

jwoa opened this issue Nov 26, 2023 · 13 comments

Comments

@jwoa
Copy link

jwoa commented Nov 26, 2023

Hey,

Thanks for the great template and Medusa in general! Everything works great locally but when trying to deploy the latest frontend/storefront on Vercel I keep running into an unexpected JSON error.

Screenshot 2023-11-26 at 9 18 42 AM

I've tried both manually and with the deploy button and always end up here. Any suggestions or fixes?

@VariableVic
Copy link
Collaborator

Hey @jwoa, this is error usually means the storefront can't access the backend properly. Have you set the STORE_CORS env var on your server to include your Vercel storefront domain?

@jwoa
Copy link
Author

jwoa commented Nov 28, 2023

Hey @VariableVic, tried that as well but unfortunately got the same error. Could it be a chicken and egg scenario where there's no domain because the site can't initially be provisioned in vercel?

Screenshot 2023-11-27 at 7 46 43 PM

@oguzergul
Copy link

Hey @VariableVic, I'm encountering the same issue with my Vercel starter. While my backend service deployed on Render is functioning correctly, I'm having trouble deploying the storefront on Vercel.

@estebankra
Copy link

I've encountered the same error. I can reproduce it in my local environment too when the backend is offline.

I found that the issue might be related to this specific line of code.
Screenshot from 2023-11-28 21-37-02

Upon commenting out that line, I was able to successfully deploy the changes on Vercel. Does anyone have any idea of why this line is causing deployment issues?

@estebankra
Copy link

estebankra commented Nov 29, 2023

I found that the error comes from this 'fetch' operation within the 'medusaRequest' when the getCollectionsList is called
image

@jwoa
Copy link
Author

jwoa commented Nov 29, 2023

@estebankra Thanks for that! It solved the Vercel deployment issue. Just have to sort the products loading now/CORS

@VariableVic
Copy link
Collaborator

Thanks for the info @estebankra! I can't reproduce this issue locally, even with a fresh install with no collections/products in it. It just returns an empty array and displays no collections on the homepage (like it should). I'll spend some more time on debugging this today.

Just to make sure, have you set the NEXT_PUBLIC_MEDUSA_BACKEND_URL env variable in Vercel? This should be your backend url without trailing / or /store.

@estebankra
Copy link

@jwoa Check out what @VariableVic said in his comment

"Just to make sure, have you set the NEXT_PUBLIC_MEDUSA_BACKEND_URL env variable in Vercel? This should be your backend url without trailing / or /store."

It looks like I first put my URL in my environment by including / at the end like https://backend.example.com/, because now that I checked my env and undo my changes, the deploy works without needing to comment any lines.

@hmmhmmhm
Copy link

hmmhmmhm commented Dec 3, 2023

Thanks for the info @estebankra! I can't reproduce this issue locally, even with a fresh install with no collections/products in it. It just returns an empty array and displays no collections on the homepage (like it should). I'll spend some more time on debugging this today.

Just to make sure, have you set the NEXT_PUBLIC_MEDUSA_BACKEND_URL env variable in Vercel? This should be your backend url without trailing / or /store.

This seems to be the problem. I succeeded by removing the / at the end of NEXT_PUBLIC_MEDUSA_BACKEND_URL.

@pmltechpile
Copy link

Getting the same error but my NEXT_PUBLIC_MEDUSA_BACKEND_URL does not have the trailing / at the end. Not sure what else it could be

@Dalvae
Copy link

Dalvae commented Dec 9, 2023

I'm having the same error as @pmltechpile I bypass the deploy error by commenting the line like @estebankra says, but that's not the way to solve it, because its not showing the products on the main page. My CORS are god, I can tell because I can get products from the products sections.

I got some intuitions that there is problem with categories or something.

@VariableVic
Copy link
Collaborator

@pmltechpile @Dalvae The unexpected token < ... error usually means Vercel couldn't reach the Medusa backend server properly. If there was an issue with your collections, Medusa would most likely throw a different error or just return an empty array. Can you check your Medusa server logs when you run the Vercel deployment and see if the request ever actually reaches the server?

@Dalvae
Copy link

Dalvae commented Dec 9, 2023

@VariableVic I tried a redeploy and nothing reaches the server

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants