You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
nitro/vite in node preset should serve public assets from the server folder and not going up to the public directory #3868
The Node preset generates two folders: .output/server and .output/public. The server folder appears to be self-contained, including its own node_modules and all the build files (in this example, there’s no node_modules directory because there are no dependencies):
❯ ls .output/public
assets/ vite.svg
❯ ls .output/server/
index.mjs package.json vite.svg
However, the server tries to read public files from outside that folder:
If I deploy only the server folder (inside a container or anywhere) the ../public folder will not be present. On the other hand if I deploy the entire .output folder the node_modules won’t work as expected.
At the moment, I’m manually duplicating the node_modules folder and loading up both folders, which doesn’t seem to be the intended approach.
You should upload or add .output to the docker container as output.
Nitro node server, by default, serves static assets. You can disable behavior using serveStatic: false config if only want to include .output/server and serve .output/public via CDN/Proxy directly.
OK, I don't mind serving the assets duplicated from the CDN and having the option is awesome too. But there's something I don't quite understand: why are there libraries in .output/server/node_modules? Node doesn't seem to look for them in that location when I run node .output/server/index.mjs.
I initially assumed it was a self-contained folder, but I guess that’s not the case.
In any case, I'll go ahead and close the issue since it turned out not to be valid.
Thank you for the explanation. I looked deeper and discovered that the missing libraries error comes from the ESM module loader interceptor added by Sentry. The raw Node module loading behavior works fine on its own so that’s not really a nitro issue.
As I was doing some experiments I noticed and got curious about the fact that nitro/vite does duplicate the content of the public folder into the server folder. What would be the advantage of doing so?
I don't even see where the server one are getting imported/used and serveStatic only refers to those in the public dir right?
If someone adds a video into the public folder this could easily end up creating triple digit artifact (ofc this doesn't make sense, why would you version control such file. But I've seen this happen multiple times out in the wild).
I currently don't see the point of having them in .output/server, especially with serveStatic: false which I assume is one of the configs used when splitting deploments (public being served via CDN/Proxy)
I do think that this should be set to false since nitro handles them. If you want I could study and work on a PR, or would you like to approach this differently or yourself?
Activity
coderabbitai commentedon Dec 12, 2025
🔗 Similar Issues
Possible Duplicates
Related Issues
publicAssetswithmaxAgenot working in some cases #3587cloudflare-modulecommands are incorrect with `compatibilityDate: 'latest' #3386outputcauses broken server bundles when usingnetlifypreset #3392emitFile({ type: 'asset' })#3577🔗 Related PRs
#3798 - perf!: remove
nodeModulesDirs[merged]#3817 - fix(vite): skip early dev handler for special prefixes [merged]
#3836 - refactor: env runners [merged]
#3849 - feat: lib chunks [merged]
#3854 - refactor(vite): keep SSR bundle external dependencies [merged]
👤 Suggested Assignees
Enable issue planning
To enable issue planning, add the following to your
.coderabbit.yaml:You can then request a plan by commenting
@coderabbitai planon any issue.🧪 Issue enrichment is currently in early access.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:pi0 commentedon Dec 12, 2025
You should upload or add
.outputto the docker container as output.Nitro node server, by default, serves static assets. You can disable behavior using
serveStatic: falseconfig if only want to include.output/serverand serve.output/publicvia CDN/Proxy directly.ernestoalejo commentedon Dec 13, 2025
OK, I don't mind serving the assets duplicated from the CDN and having the option is awesome too. But there's something I don't quite understand: why are there libraries in
.output/server/node_modules? Node doesn't seem to look for them in that location when I runnode .output/server/index.mjs.I initially assumed it was a self-contained folder, but I guess that’s not the case.
In any case, I'll go ahead and close the issue since it turned out not to be valid.
pi0 commentedon Dec 14, 2025
.output is a self contained dir thats why Nitro traces dependencies into it.
With node resolution algorithm, closest node_modules dir to importer will be searched first.
ernestoalejo commentedon Dec 14, 2025
Thank you for the explanation. I looked deeper and discovered that the missing libraries error comes from the ESM module loader interceptor added by Sentry. The raw Node module loading behavior works fine on its own so that’s not really a nitro issue.
Thanks for your time!
sandros94 commentedon Feb 5, 2026
As I was doing some experiments I noticed and got curious about the fact that nitro/vite does duplicate the content of the public folder into the server folder. What would be the advantage of doing so?
I don't even see where the
serverone are getting imported/used andserveStaticonly refers to those in thepublicdir right?If someone adds a video into the public folder this could easily end up creating triple digit artifact (ofc this doesn't make sense, why would you version control such file. But I've seen this happen multiple times out in the wild).
I currently don't see the point of having them in
.output/server, especially withserveStatic: falsewhich I assume is one of the configs used when splitting deploments (public being served via CDN/Proxy)pi0 commentedon Feb 5, 2026
It is likely a vite misconfig issue that this happens. shouldn't happen with nitro cli / rolldown.
sandros94 commentedon Feb 6, 2026
@pi0 thanks and indeed I've found it:
build.copyPublicDirI do think that this should be set to
falsesince nitro handles them. If you want I could study and work on a PR, or would you like to approach this differently or yourself?pi0 commentedon Feb 6, 2026
Yes please feel free to make a PR! I think we should disable it for SSR and Nitro vite env configs (only client consumers)