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

30 messages · Page 1 of 1 (latest)

dull meadow
#

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

tulip flaxBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

wide summit
#

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

dull meadow
#

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

wide summit
#

What does your .next/standalone structure currently look like?

dull meadow
#

i mentioned that above:

/.next/standalone/apps/<my app name>/…

wide summit
#

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

dull meadow
#

server.js is in the <my app name> folder

#

ya, this structure makes it so i dunno where to copy files to

wide summit
#

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.

dull meadow
#

should static/public be alongside server.js as siblings?

wide summit
#

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.

dull meadow
#

i did, static files weren’t served

wide summit
#

Server.js should also have code to detect these so if you want to snoop around in that you can

wide summit
dull meadow
#

yeah

#

was hoping someone had done it and knew heh

wide summit
#

Try copying to the folder that contains the server.js

dull meadow
#

tried that 🙂

wide summit
#

It still doesnt work?

dull meadow
#

nope

#

i have no idea where they go haha

wide summit
#

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.

wide summit
dull meadow
#

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