Skip to content

Nextjs app with a basePath assets don't load #6655

@willwashburn

Description

@willwashburn

Bug:

NextJs app with basePath results in assets 403'ing

How to reproduce

run npx sst deploy on this repo

https://github.com/willwashburn/sst-basepath-assets-issues

load the index page. assets get 403'd

Expected

With basePath: "/example-base-path", these should resolve:

  • GET /example-base-path/_next/static/... -> 200
  • GET /example-base-path/favicon.svg -> 200

Actual

The HTML references base-path-prefixed assets, but only root asset paths work:

  • GET /example-base-path/_next/static/... -> 403
  • GET /_next/static/... -> 200
  • GET /example-base-path/favicon.svg -> 403
  • GET /favicon.svg -> 200

Root Cause

This looks like an SST CloudFront router bug.

OpenNext v3.9.16 emits base-path-aware S3 copy metadata:

https://github.com/opennextjs/opennextjs-aws/blob/v3.9.16/packages/open-next/src/build/generateOutput.ts#L198-L208

But SST’s router strips the base path only for matching, then reuses the original request URI when rewriting to S3

So a request like:

  • /example-base-path/_next/static/chunks/app.css

matches using:

  • /_next/static/chunks/app.css

but gets rewritten to S3 as:

  • /_assets/example-base-path/_next/static/chunks/app.css

instead of:

  • /_assets/_next/static/chunks/app.css

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions