Next.js: public is not copied into dist with custom server

Created on 29 Jul 2019  路  2Comments  路  Source: vercel/next.js

Bug report

Describe the bug

if you have a custom server, enabling the experimental public folder with { experimental: { publicDirectory: true } } will try to serve from ./dist/public, but this folder does not exists in dev. also next build does not copy it over.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. setup next with custom server like https://nextjs.org/docs#custom-server-and-routing
  2. set { experimental: { publicDirectory: true } }
  3. make /public directory, add some files
  4. start in dev mode
  5. try to access the file, it will return a 404
  6. look in ./dist, the folder is empty

Expected behavior

i am unsure how this is meant to work in the default case. I solved it by adding an additional script in package.json that copies /public over to dist (something like "rimraf ./dist/public && cp -r ./public ./dist")

https://nextjs.org/docs#custom-server-and-routing should probably mention that

System information

  • OS: macOS

  • Version of Next.js: [e.g. 9.0.2]

needs investigation

Most helpful comment

for reference:

I had a project which was based on an older typescript&customserver config where everything was built to /dist (incl. next), so only /dist would be deployed to the production environment. In this scenario, public and static folder would not automatically appear in /dist of course.

i now aligned this setup to be like in https://github.com/zeit/next.js/tree/canary/examples/custom-server-typescript

All 2 comments

@macrozone I'm unable to reproduce the issue, the public folder was working fine in my environment, feel free to re-open the issue and share a demo if the issue persists

for reference:

I had a project which was based on an older typescript&customserver config where everything was built to /dist (incl. next), so only /dist would be deployed to the production environment. In this scenario, public and static folder would not automatically appear in /dist of course.

i now aligned this setup to be like in https://github.com/zeit/next.js/tree/canary/examples/custom-server-typescript

Was this page helpful?
0 / 5 - 0 ratings

Related issues

irrigator picture irrigator  路  3Comments

kenji4569 picture kenji4569  路  3Comments

wagerfield picture wagerfield  路  3Comments

knipferrc picture knipferrc  路  3Comments

rauchg picture rauchg  路  3Comments