Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app dir setAssetPrefix not work #51223

Closed
1 task done
xingyibiao opened this issue Jun 13, 2023 · 8 comments · Fixed by #61676
Closed
1 task done

app dir setAssetPrefix not work #51223

xingyibiao opened this issue Jun 13, 2023 · 8 comments · Fixed by #61676
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked

Comments

@xingyibiao
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
    Binaries:
      Node: 16.14.0
      npm: 8.3.1
      Yarn: 1.22.19
      pnpm: 8.5.1
    Relevant packages:
      next: 13.4.6-canary.0
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.0.4

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue or a replay of the bug

https://codesandbox.io/p/sandbox/frosty-yalow-phg76g?file=%2Fnext.config.js%3A3%2C27

To Reproduce

custom server app dir setAssetPrefix not work in my local server. I don't know how to fix it

Describe the Bug

custom server app dir setAssetPrefix not work
image

Expected Behavior

all static asset should with custom prefix like: 'https://www.baidu.com/_next/static/chunk/xxx.js'

Which browser are you using? (if relevant)

Chrome 100.0.4878.0

How are you deploying your application? (if relevant)

custom server (http)

@xingyibiao xingyibiao added the bug Issue was opened via the bug report template. label Jun 13, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label Jun 13, 2023
@xingyibiao
Copy link
Author

Is anyone following up this issue?

@xingyibiao
Copy link
Author

Does app router won`t support custom server to setAssetPrefix?

@nicolaturcato
Copy link

nicolaturcato commented Nov 29, 2023

Bringing up this issue. Same happens to me starting from v13.5, it was working perfectly fine on v13.4.7.
SetAssetPrefix stopped working on my custom server.
As we can see from @xingyibiao example the asset prefix is not set on a production build.

@xingyibiao
Copy link
Author

I fix it by set dynamic = 'force-dynamic'

// layout.tsx
export const dynamic = 'force-dynamic'

the reason is use file cache by default, so always is next.config.js assetPrefix

@xingyibiao
Copy link
Author

It just work on v13.4.x
below v13.5

I fix it by set dynamic = 'force-dynamic'

// layout.tsx
export const dynamic = 'force-dynamic'

the reason is use file cache by default, so always is next.config.js assetPrefix

It just work on 13.4.1(my version), 13.5.x not work

@xingyibiao xingyibiao reopened this Dec 26, 2023
@shaunwarman
Copy link

Would a workaround be conditionally setting assetPrefix in next.config.js?

const assetPrefix = process.env.NODE_ENV === 'production' ? https://mycdn.com : undefined;

/** @type {import('next').NextConfig} */
const nextConfig = {
  assetPrefix,
  ...
};

module.exports = nextConfig;

@nicolaturcato
Copy link

Would a workaround be conditionally setting assetPrefix in next.config.js?

const assetPrefix = process.env.NODE_ENV === 'production' ? https://mycdn.com : undefined;

/** @type {import('next').NextConfig} */
const nextConfig = {
  assetPrefix,
  ...
};

module.exports = nextConfig;

It doesn't work either unfortunately.

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants