Next.js: Public assets with subPath don't work in production build

Created on 17 Sep 2020  路  6Comments  路  Source: vercel/next.js

Bug report

Public assets with subPath don't work in production build

To Reproduce

  1. npx create-next-app
  2. Add next.config.js with content
module.exports = {
  basePath: '/test/sub-path',
  trailingSlash: false,
}
  1. Edit file pages/index.js and replace line
<img src="/vercel.svg" alt="Vercel Logo" className={styles.logo} />

with

<img src="/test/sub-path/vercel.svg" alt="Vercel Logo" className={styles.logo} />
  1. Run dev application npm run dev - everything works fine
  2. Run prod application npm run build npm run start - static image asset doesn't work - 404

Expected behavior

Public assets should work in dev and prod

System information

  • OS: macOs
  • Version of Next.js: 9.5.3
  • Version of Node.js: v13.14.0
good first issue bug

All 6 comments

I am experiencing the exact same issue today on an identical system.

Interestingly, building a static site with next export does work, which leads me to believe it's the next server module itself where the bug lies.

Yes, and it works on 9.5.2 correctly

Any progress on it?

This is also preventing us from upgrading past 9.5.2. I see that a PR was already opened, but I may take a crack at it if it will get us moving forward on this fix.

Is there any workaround for this issue while the fix is ready?

@ricardoGlobant I have worked around this by using the custom server setup of Next JS and using express static to serve those files. This is _ok_ but obviously comes with all the downsides of using a custom server.

https://nextjs.org/docs/advanced-features/custom-server
https://expressjs.com/en/starter/static-files.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rauchg picture rauchg  路  3Comments

sospedra picture sospedra  路  3Comments

knipferrc picture knipferrc  路  3Comments

YarivGilad picture YarivGilad  路  3Comments

formula349 picture formula349  路  3Comments