Skip to content

/_image returns 500 in Node standalone when dist is moved (absolute file:/// paths baked into output) #15087

@abcfy2

Description

@abcfy2

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.url fixes the issue.

Reproduction Steps

  1. Configure adapter: node({ mode: "standalone" }) with output: "server".
  2. astro build.
  3. Move the dist/ folder (or the standalone output folder) to a different path (E.g: pnpm --filter . deploy ./deploy --legacy).
  4. Run: node dist/server/entry.mjs.
  5. Request a local optimized image, e.g. /_image?href=%2F_astro%2Flogo.hash>.png&w=64&h=64&f=webp.
  6. 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

https://stackblitz.com/github/withastro/astro/tree/latest/examples/blog?on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: nodeRelated to Node adapter (scope)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions