next.js icon indicating copy to clipboard operation
next.js copied to clipboard

dynamic assetPrefix not working in "standalone" build, because of serialization

Open lionskape opened this issue 1 year ago • 1 comments

Link to the code that reproduces this issue

https://github.com/lionskape/next-standalone-assetprefix-bugrepot/blob/main/next.config.js

To Reproduce

  1. create next config like this:
let nextConfig = {
    output: 'standalone',
    assetPrefix: process.env.CDN_URI ?? '',
};
  1. run next build without CDN_URI variable
  2. run nextjs server CDN_URI="https://cdn.net" node .next/standalone/server.js

Current vs. Expected behavior

Current behavior: No prefix will be added to resources because of config serialization - https://github.com/vercel/next.js/blob/81d5daddf365943e3f2c3a258d00c8ac76f9c81c/packages/next/src/build/utils.ts#L2116

Expected behavior: dynamic assetPrefix works fine, environment variable is consumed.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 18.17.1
  npm: 9.6.7
  Yarn: N/A
  pnpm: 7.32.1
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Output (export/standalone), Runtime

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

No response

lionskape avatar May 15 '24 18:05 lionskape

I am currently running into the same issue

JulienKode avatar Oct 23 '24 07:10 JulienKode

I am also running into this issue, previously assetPrefix worked.

Chasewhip8 avatar Nov 12 '24 19:11 Chasewhip8

same issue, is there any news

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

hvsy avatar Feb 17 '25 15:02 hvsy

Faced similar issues, ended up using something like: https://github.com/vercel/next.js/discussions/18301#discussioncomment-113660

Netail avatar Sep 26 '25 22:09 Netail