Next.js Discord

Discord Forum

what is the output structure of output:standalone supposed to be?

Unanswered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
i have a NextJs 14 /app app (14.1.4) in a monorepo as a subdirectory, and when i do next build with output: standalone in config, i don’t get the structure the docs say i should.

the server.js isn’t in the root of the standalone directory. it’s nested under a structure like:

/dist/standalone/apps/<my app name>/server.js

there’s also the other folders there that look like they are remnants from other build types in /dist. as if NextJS creates the build as normal, then copies things into /dist/standalone but doesn’t clean up after copying.

is that expected? if so, how much of the /dist/standalone do i actually need to copy over if i wanna deploy it? and where should i copy the public and static dirs?

the docs that i have found say nothing about it

29 Replies

A standalone build simply traces all files that are going to be used by your pages and copies them in a folder. This allows you to copy the folder over ftp and not have to install node_modules or anything extra.

The 3 folders you need to be looking out for are:
- .next/standalone
- public
- .next/static

The public and .next/static folders can be deployed to a cdn OR moved to the standalone folder if you dont want to host your static files on a cdn.

Lastly you can either use next run OR run server.js
Asiatic LionOP
i get that.

my question is about the dir structure itself. the docs don’t mention what the shape of the standalone dir will be. the docs say there will be a server.js in the root of the standalone dir, but that isn’t the case in my env. so i can’t use the docs to figure out how/where to copy static/public files
What does your .next/standalone structure currently look like?
Asiatic LionOP
i mentioned that above:

/.next/standalone/apps/<my app name>/…
Btw i also thought the server.js should be output to the root of the standalone folder but the docs dont explicitly say that. They just say a server.js file is output.

Additionally, a minimal server.js file is also output which can be used instead of next start
Asiatic LionOP
server.js is in the <my app name> folder
ya, this structure makes it so i dunno where to copy files to
Also this part:
This minimal server does not copy the public or .next/static folders by default as these should ideally be handled by a CDN instead, although these folders can be copied to the standalone/public and standalone/.next/static folders manually, after which server.js file will serve these automatically.
Asiatic LionOP
should static/public be alongside server.js as siblings?
How about you try doing this first ig :/. Just test it out on your local environment rq. If the static stuff works you know it's fine.
Asiatic LionOP
i did, static files weren’t served
Server.js should also have code to detect these so if you want to snoop around in that you can
@Asiatic Lion i did, static files weren’t served
Then maybe the docs are outdated :/
Asiatic LionOP
yeah
was hoping someone had done it and knew heh
Try copying to the folder that contains the server.js
Asiatic LionOP
tried that 🙂
It still doesnt work?
Asiatic LionOP
nope
i have no idea where they go haha
That is quite weird. Ig last effort would be ensuring you have latest next version, deleting the .next folder and then doing the build again
Otherwise, put up a issue on GitHub ig.
@Asiatic Lion i have no idea where they go haha
Did you figure this out?
Asiatic LionOP
yep
so there are two .next folders as it turns out
a top level and a nested one.
for me they are named dist cuz i have an outDir configured
so the public folder gets copied as a sibling to the nested dist. and the static folder gets copied inside the nested dist
for me it looks like:
/dist/standalone/apps/my-app/dist/static
/dist/standalone/apps/my-app/public