withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.8k stars 2.49k forks source link

Javascript API routes throw an error in hybrid rendering mode if set to render dynamically #11283

Closed varialweb closed 3 months ago

varialweb commented 4 months ago

Astro Info

Astro                    v4.10.1
Node                     v20.9.0
System                   Windows (x64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/vercel/serverless
Integrations             @astrojs/tailwind
                         @astrojs/svelte

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

If you have the project configured to hybrid rendering, and your API route uses javascript and you set export const prerender = false it will throw the error:

A prerender export has been detected, but its value cannot be statically analyzed.
Expected false value but got false .

It does not throw this error if you change the file to typescript.

What's the expected result?

I would expect the prerender const to work properly regardless of using typescript or javascript.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-7ycbzn?file=src%2Fcomponents%2FContactForm.svelte

Participation

varialweb commented 4 months ago

Also I tried to get this working in StackBlitz, but the API routes wont work at all for me in there, so in order to reproduce this, you may have to create it locally on your machine.

ematipico commented 4 months ago

Also I tried to get this working in StackBlitz, but the API routes wont work at all for me in there, so in order to reproduce this, you may have to create it locally on your machine.

So just downloading the stackblitz repository is enough?

matthewp commented 4 months ago

That is pretty odd, will take a look.

matthewp commented 3 months ago

Where do you get that error message? I just tried and it built cleanly. Dev also appears to work fine.

nick-cjyx9 commented 3 months ago

Where do you get that error message? I just tried and it built cleanly. Dev also appears to work fine.

In the min reproduction @varialweb gave, just delete the ; of export const prerender = false; in /src/pages/api/contact.js. And you will get the same error.

image