Next.js Discord

Discord Forum

Serving static JS file

Answered
Mexican Chickadee posted this in #help-forum
Open in Discord
Mexican ChickadeeOP
Hello everyone!

In Next 12 it was possible to have JS files in public directory and they were served correctly. When I moved to Next 13 it seems that no longer works. Did I miss something? It works when I run server locally, in dev mode and after build, but after deploying to Vercel it's gone.
Answered by Mexican Chickadee
I think I might found the issue actually. Those scripts that I put in public are built before next build. Build files are placed within public folder and picked up by Next during the build. Right now, the same occured after downgrading to Next 12 and I was wondering what happened. I've checked last build and it was missing these built scripts in the summary. After I've redeployed the site without the build cache it was created correctly.
View full answer

12 Replies

Mexican ChickadeeOP
@joulev The public directory indeed works normally, but have you tried put a JS file there?
Mexican ChickadeeOP
Well... thank you @joulev for your time. I had to miss something somwhere, but where.... I don't know
Remove irrelevant parts of your code chunk by chunk and try to reduce the codebase to a very minimal form
Until the problem vanishes
Mexican ChickadeeOP
I think I might found the issue actually. Those scripts that I put in public are built before next build. Build files are placed within public folder and picked up by Next during the build. Right now, the same occured after downgrading to Next 12 and I was wondering what happened. I've checked last build and it was missing these built scripts in the summary. After I've redeployed the site without the build cache it was created correctly.
Answer
Mexican ChickadeeOP
Thank you again @joulev for your time!
No worries, glad you fixed it