Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Static preset doesn't work [Nitro 3.0.1-alpha.1] #3843

@syahzuan

Description

@syahzuan

Environment

Nitro: 3.0.1-alpha.1
Vite: 7.2.6

Reproduction

I am using this example from nitro repo with only one change - adding the static preset.

Example: https://github.com/nitrojs/nitro/tree/main/examples/vite-ssr-vue-router
Change:

//
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
import devtoolsJson from "vite-plugin-devtools-json";
import { nitro } from "nitro/vite";

export default defineConfig((_env) => ({
    plugins: [patchVueExclude(vue(), /\?assets/), devtoolsJson(), nitro()],
    environments: {
        client: {
            build: { rollupOptions: { input: "./app/entry-client.ts" } },
        },
        ssr: { build: { rollupOptions: { input: "./app/entry-server.ts" } } },
    },
    nitro: {
        preset: "static",
        prerender: {
            routes: ["/", "about"],
        },
    },
}));

// Workaround https://github.com/vitejs/vite-plugin-vue/issues/677
function patchVueExclude(plugin, exclude) {
    const original = plugin.transform.handler;
    plugin.transform.handler = function (...args) {
        if (exclude.test(args[1])) return;
        return original.call(this, ...args);
    };
    return plugin;
}

Describe the bug

Building with non-static preset such as default, 'vercel', 'cloudflare_pages' succeed.
Building with static preset such as 'static', 'vercel-static, 'cloudflare_pages_static' fail with this error message:

error during build:
rollupOptions.input should not be an html file when building for SSR. Please specify a dedicated SSR entry.
    at resolveRollupOptions (file:///home/syahzuan/projects/personal/vue-ssg/nitro-v3-vue-ssr-example/node_modules/vite/dist/node/chunks/config.js:33451:73)
    at buildEnvironment (file:///home/syahzuan/projects/personal/vue-ssg/nitro-v3-vue-ssr-example/node_modules/vite/dist/node/chunks/config.js:33506:25)
    at Object.build (file:///home/syahzuan/projects/personal/vue-ssg/nitro-v3-vue-ssr-example/node_modules/vite/dist/node/chunks/config.js:33899:25)
    at buildEnvironments (file:///home/syahzuan/projects/personal/vue-ssg/nitro-v3-vue-ssr-example/node_modules/nitro/dist/_build/vite.plugin.mjs:186:16)
    at async Object.buildApp (file:///home/syahzuan/projects/personal/vue-ssg/nitro-v3-vue-ssr-example/node_modules/vite/dist/node/chunks/config.js:33893:5)
    at async CAC.<anonymous> (file:///home/syahzuan/projects/personal/vue-ssg/nitro-v3-vue-ssr-example/node_modules/vite/dist/node/cli.js:629:3)
error: script "build" exited with code 1

Additional context

I am a beginner learning to integrate Nitro at a lower level without framework. Apology in advance if I am missing something.

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions