-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
Astro Info
Astro v5.16.6
Node v24.12.0
System Linux (x64)
Package Manager pnpm
Output server
Adapter @astrojs/node
Integrations @inox-tools/sitemap-ext
@astrojs/mdx
@astrojs/react
mona-kiosk (v0.2.1)
If this issue only occurs in one browser, which browser is a problem?
Not browser specific.
Describe the Bug
In output: "server" + @astrojs/node standalone mode, the built output embeds absolute file URLs pointing to the build machine’s paths (e.g. file:///.../dist/client/).
When the build output is deployed to a different directory (e.g. /opt/training or a container mount), the /_image endpoint fails with 500 because the server tries to read local images from the original build path.
This only happens in the deployed environment; local astro preview works.
Symptoms:
/_image?...returns 500 for local assets.- No server error log (because the internal loader returns undefined and responds 500 without throwing).
- Editing the built output to use relative paths based on
import.meta.urlfixes the issue.
Reproduction Steps
- Configure adapter:
node({ mode: "standalone" })withoutput: "server". astro build.- Move the
dist/folder (or the standalone output folder) to a different path (E.g:pnpm --filter . deploy ./deploy --legacy). - Run:
node dist/server/entry.mjs. - Request a local optimized image, e.g.
/_image?href=%2F_astro%2Flogo.hash>.png&w=64&h=64&f=webp. - Observe 500 error.
For example. When I use pnpm build, then check dist/server/entry.mjs, will find this hardcoded path:
const _args = {
"mode": "standalone",
"client": "file:///home/fengyu/projects/DTeam-Top/training/dist/client/",
"server": "file:///home/fengyu/projects/DTeam-Top/training/dist/server/",
"host": false,
"port": 4321,
"assets": "_astro",
"experimentalStaticHeaders": false
};And also in dist/server/chunk/_astro_assets_*.mjs:
const outDir = /* #__PURE__ */ new URL("file:///home/fengyu/projects/DTeam-Top/training/dist/client/");This will cause can't move dist/ to other path. Please fix it.
Maybe new URL(..., import.meta.url).href is a good idea ?
What's the expected result?
When using the Node adapter in standalone mode, the built server should be portable: moving dist/ (and the standalone bundle) to another directory or machine should not break the /_image endpoint. Image optimization for local assets should continue to work.
Link to Minimal Reproducible Example
Participation
- I am willing to submit a pull request for this issue.