Skip to content

nitro/vite in node preset should serve public assets from the server folder and not going up to the public directory #3868

@ernestoalejo

Description

@ernestoalejo

Environment

nitro 3.0.1-alpha.1
node v22.14.0

Reproduction

  1. Empty vite project (https://vite.new)
  2. Install nitro: npm i nitro + add vite.config.ts with the plugin.
  3. npm run build

Example project:
https://stackblitz.com/edit/vitejs-vite-1gfcfxdy

Describe the bug

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:

const assets = {
  "/vite.svg": {
    "type": "image/svg+xml",
    "etag": '"5d9-9/Odcje3kalF1Spc16j7Nl8xM2Y"',
    "mtime": "2025-12-12T12:34:55.909Z",
    "size": 1497,
    "path": "../public/vite.svg"
  },
  "/assets/index-CgYMNPpC.js": {
    "type": "text/javascript; charset=utf-8",
    "etag": '"a18-LiowwUS0J37fkDvNtFxd7Bs1Pik"',
    "mtime": "2025-12-12T12:34:56.009Z",
    "size": 2584,
    "path": "../public/assets/index-CgYMNPpC.js"
  },
  "/assets/index-XlyKSLnJ.css": {
    "type": "text/css; charset=utf-8",
    "etag": '"4b0-UhNyv0a4d7OTwpHmdOyfIisUpMQ"',
    "mtime": "2025-12-12T12:34:56.009Z",
    "size": 1200,
    "path": "../public/assets/index-XlyKSLnJ.css"
  }
};
function readAsset(id) {
  const serverDir = dirname(fileURLToPath(globalThis.__nitro_main__));
  return promises.readFile(resolve(serverDir, assets[id].path));
}

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.

COPY .output .output
COPY .output/server/node_modules node_modules

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions