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

@astrojs/vercel - AdapterSupportOutputMismatch #430

Open
1 task
phenomen opened this issue Oct 31, 2024 · 5 comments
Open
1 task

@astrojs/vercel - AdapterSupportOutputMismatch #430

phenomen opened this issue Oct 31, 2024 · 5 comments
Assignees
Labels
- P4: important Violate documented behavior or significantly improves performance (priority) pkg: vercel Related to Vercel adapter (scope)

Comments

@phenomen
Copy link

Astro Info

Astro                    v5.0.0-beta.6
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/vercel
Integrations             none

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

No response

Describe the Bug

After upgrading to "astro": "5.0.0-beta.6" and "@astrojs/vercel": "8.0.0-beta.3" I get an error:

[AdapterSupportOutputMismatch] The `@astrojs/vercel` adapter is configured to output a static website, but the project contains server-rendered pages. Please install and configure the appropriate server adapter for your final deployment.
  Error reference:
    https://docs.astro.build/en/reference/errors/adapter-support-output-mismatch/
  Stack trace:
    at new AstroError (file:///home/projects/withastro-astro-fewhsc/node_modules/astro/dist/core/errors/errors.js:37:5)
    at setAdapter (file:///home/projects/withastro-astro-fewhsc/node_modules/astro/dist/integrations/hooks.js:265:45)
    at Module.runHookConfigDone (file:///home/projects/withastro-astro-fewhsc/node_modules/astro/dist/integrations/hooks.js:262:59)
    at async AstroBuilder.run (file:///home/projects/withastro-astro-fewhsc/node_modules/astro/dist/core/build/index.js:196:23)
    at async build (file:///home/projects/withastro-astro-fewhsc/node_modules/astro/dist/cli/build/index.js:44:3)
 ELIFECYCLE  Command failed with exit code 1.

From what I understand, static is a correct output if just a few pages/endpoints have export const prerender = false;

In the linked reproduction, run npm run build to repro the error.

What's the expected result?

Successful build.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-fewhsc?file=package.json

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Oct 31, 2024
@bluwy bluwy transferred this issue from withastro/astro Nov 1, 2024
@bluwy
Copy link
Member

bluwy commented Nov 1, 2024

Looks like we need to update the vercel adapter code here to use the value of buildOutput from the astro:config:done hook instead of from the astro:config:setup hook:

'astro:config:done': ({ setAdapter, config }) => {
if (buildOutput === 'server') {
setAdapter(getAdapter({ buildOutput, edgeMiddleware, middlewareSecret, skewProtection }));
} else {
setAdapter(
getAdapter({
edgeMiddleware: false,
middlewareSecret: '',
skewProtection,
buildOutput,
})
);
}
. That way setAdapter uses the right value that doesn't trigger the error.

That solves this issue, however it also looks like vercel is using the buildOutput during astro:config:setup, which is a little problematic because that's not the final value yet.

'astro:config:setup': async ({ command, config, updateConfig, injectScript, logger }) => {
buildOutput = config.output;
if (webAnalytics?.enabled) {
injectScript(
'head-inline',
await getInjectableWebAnalyticsContent({
mode: command === 'dev' ? 'development' : 'production',
})
);
}
if (buildOutput === 'server') {

Unless there's a way to share the same config in agnostic of server or static, @ematipico I think making @astrojs/adapter as a single entrypoint might not work here. Perhaps you have some ideas to fix this.

@ematipico
Copy link
Member

which is a little problematic because that's not the final value yet.

Is there a case where buildOutput starts as server but then the final value is static?

@bluwy
Copy link
Member

bluwy commented Nov 1, 2024

It should only ever go from static to server based on this code: https://github.com/withastro/astro/blob/731b69712b0e9c5d5a4058db3fa3e8bf628c7aad/packages/astro/src/core/routing/manifest/prerender.ts#L28

I've discussed with Erika before if we could detect the case where the user set server but every route is set to prerender true, in which it should ended up as static, but we didn't implement it as it doesn't make sense to do so in practice.

@princemuel
Copy link

I'm also experiencing this problem

@ematipico ematipico self-assigned this Nov 8, 2024
@ematipico ematipico added - P4: important Violate documented behavior or significantly improves performance (priority) pkg: vercel Related to Vercel adapter (scope) and removed needs triage Issue needs to be triaged labels Nov 8, 2024
@samparmenter
Copy link

samparmenter commented Nov 28, 2024

Having the same issue here. Output set to static as almost the entire site is static bar a couple of /api routes but using the @astro/vercel adaptor I am seeing The @astrojs/vercel adapter is configured to output a static website, but the project contains server-rendered pages. Please install and configure the appropriate server adapter for your final deployment.

In the single api route I currently have I have export default prerender = false;

Using the @astro/node adapter it all works as expected locally and respects the idea that all pages are static unless the 'opt out' of prerendering has been set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly improves performance (priority) pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
Development

No branches or pull requests

5 participants