@astro/vercel: Astro emits code that has client:only
on SSR since vite 3.2.5, when importsNotUsedAsValues is set
#5624
Labels
- P4: important
Violate documented behavior or significantly impacts performance (priority)
What version of
astro
are you using?1.7.1 (broke starting on 1.6.13)
Are you using an SSR adapter? If so, which one?
Vercel
What package manager are you using?
pnpm
What operating system are you using?
Mac
Describe the Bug
When using
tsconfig.json
's"importsNotUsedAsValues": "error"
option, as set on packages/astro/tsconfigs/strict.json, building with the@astro/vercel
integration emits code for components that haveclient:only="react"
inside thevercel/output/functions/render.func/dist/entry.js
serverless function.That is incorrect and causes the runtime to break when packages are incompatible with server rendering.
With that setting removed, the code is not present.
Working example:
WesSouza/astro-vite-vercel-issue
https://astro-vite-vercel-issue.vercel.app/
Breaking change:
https://github.com/WesSouza/astro-vite-vercel-issue/pull/2
https://astro-vite-vercel-issue-git-broken-wessouza.vercel.app/
Logs are public here
Runtime error on Vercel:
I suspect that the emitted entry.js code is importing modules that are themselves not added to the build, causing these import errors (there is another one on the original details below).
Original investigation and details
TL;DR: Vercel output broke when
vite
went from 3.2.4 to 3.2.5, which happened on 1.6.13.Basically, ever since
vite@3.2.5
, Astro started adding frotnend code tovercel/dist/entry.js
which is breaking the deployment.This one is a doozy, I've been trying to reproduce it on a clean project but was unable to, so I'm referencing PRs from my own project with the issue.
Setup
@astro/react
and@astro/vercel
client:only="react"
because ofstyled-components
Problem 1:
import x from "date-fns/x"
Source on this PR: WesSouza/mastodon-flock#7.
This import breaks:
Error:
The file
npm:date-fns/formatDistanceToNow/package.json
seems correct to me, not sure why this would happen.I was able to fix this by importing directly from the
date-fns
package:Problem 2: Astro is trying to run code that has
client:only
on SSRSource on this PR: WesSouza/mastodon-flock#8.
I also noticed that the built entry.js file has much more code that was not there previously, especially imports and components that were set to
client:only="react"
.One thing that broke was
styled-components
:Link to Minimal Reproducible Example
astro@1.6.13
: WesSouza/mastodon-flock#7astro@1.6.13
: WesSouza/mastodon-flock#8astro@1.7.1
: WesSouza/mastodon-flock#9I suspect the change that affects me was introduced by vitejs/vite@eba9b42, specifically vitejs/vite#11123, but I'm not sure.
Link to Minimal Reproducible Example
https://github.com/WesSouza/astro-vite-vercel-issue/pull/2
Participation
The text was updated successfully, but these errors were encountered: