router icon indicating copy to clipboard operation
router copied to clipboard

Start: Custom Nitro config, post vinxi→vite migration

Open djgrant opened this issue 7 months ago • 10 comments

Which project does this relate to?

Start

Describe the bug

Firstly, amazing work with the migration away from vinxi that dropped in 1.120. Unexpected, but awesome nonetheless.

On the old setup, I previously was able to configure nitro, e.g.:

// app.config.ts
server: {
  preset: 'aws-lambda',
  awsLambda: {
    streaming: true
  }
}

Now, I am only able to set target i.e. nitro's preset field, but not pass any additional nitro config.

Suggested fix

// vite.config.ts
tanstackStart({
  nitro: {
    preset: 'aws-lambda',
    awsLambda: {
      streaming: true
    }
  }
})
  • nitro would be spread on top of https://github.com/TanStack/router/blob/main/packages/start-plugin-core/src/nitro-plugin/plugin.ts#L73-L103
  • optionally, nitro could accept a merge function

If it's not already in the works, I am willing to submit a PR.

Your Example Website or App

https://codesandbox.io/p/devbox/github/tanstack/router/tree/main/examples/react/start-basic?embed=1&file=%2Fvite.config.ts&theme=dark

Steps to Reproduce the Bug or Issue

  • Open sandbox
  • Try passing nitro config params to tanstackStart vite plugin

Expected behavior

I can continue to pass nitro config to the build server

Screenshots or Videos

No response

Platform

Any platform

Additional context

No response

djgrant avatar Jun 12 '25 16:06 djgrant

This would be great. Currently facing the same struggle.

isot0pe avatar Jun 12 '25 23:06 isot0pe

This can be resolved by creating a nitro.config.ts in the same directory.

export default defineNitroConfig({
  awsLambda: {
    streaming: true,
  },
});

djgrant avatar Jun 13 '25 12:06 djgrant

It seems like all the options can be added / augmented except for compatibility date

There are more recent versions of the build instructions from nitro that currently can't be used because the compatibility date can't be overridden.

Is there a way to either allow users to enter their own compatibility date, or at the very least change it to "latest" so we can pick up recent additions?

litewarp avatar Jun 13 '25 13:06 litewarp

Running into the same issue, unable to build for aws-lambda on the latest tanstack router / start version using vite.config.js instead of app.config.ts; it always builds for node-server

K-Mistele avatar Jun 13 '25 15:06 K-Mistele

This can be resolved by creating a nitro.config.ts in the same directory.

export default defineNitroConfig({ awsLambda: { streaming: true, }, });

This fixed it for me; also had to update the preset:

import { defineNitroConfig } from 'nitropack/config';

export default defineNitroConfig({
  preset: 'aws-lambda',
  awsLambda: {
    streaming: true,
  },
});

K-Mistele avatar Jun 13 '25 15:06 K-Mistele

Yeah. It looks like all config options except for "compatibility date" can be overridden.

Not that there are a lot of needed updates, but I figure that as new features on deno / cloudflare / netlify, etc get introduced, we should be able to support them.

https://nitro.build/deploy#compatibility-date

UPDATE: it looks like there are more updates than what's listed on the website. There's no new update for "firebaseAppHosting" listed but if you patch @tanstack/start-plugin-core and set it to latest, you'll get a compatibility date of 2025-06-08.

/* @tanstack/start-plugin-core/src/nitro-plugin/plugin.ts */

const nitroConfig: NitroConfig = {
    dev: false,
    // TODO: do we need this? should this be made configurable?
    compatibilityDate: '2024-11-19',   // <--- change to 'latest' or comment out and set in `nitro.config.ts`
    logLevel: 3,
    ...
}

Firebase App Hosting

✔ Generated public .output/public                                                                                                                                                            nitro 10:20:05 AM
ℹ Building Nitro Server (preset: firebase-app-hosting, compatibility date: 2025-06-08)                                                                                                       nitro 10:20:05 AM
✔ Nitro Server built

Cloudflare Module

ℹ Building Nitro Server (preset: cloudflare-module, compatibility date: 2025-06-08)

litewarp avatar Jun 13 '25 16:06 litewarp

This fixed it for me; also had to update the preset:

Just to clarify, I also had target set in my vite.config.ts

// vite.config.ts
tanstackStart({
  nitro: {
    preset: 'aws-lambda',
  }
})

djgrant avatar Jun 13 '25 17:06 djgrant

Also ran into this issue when I needed to set streaming. Using a custom nitro.config.ts worked as a workaround, but configuring this directly in the Vite plugin would feel more natural imho.

niklaswallerstedt avatar Jun 13 '25 19:06 niklaswallerstedt

Ref: https://github.com/TanStack/router/pull/4192

niklaswallerstedt avatar Jun 13 '25 19:06 niklaswallerstedt

we will most likely decouple start from nitro and add a separate start-nitro vite plugin. this start-nitro plugin can then contain all the config for nitro

schiller-manuel avatar Jun 13 '25 19:06 schiller-manuel

I know start is still v0 but shipping a huge breaking change with no docs is pretty painful!

sfc-gh-alisowski avatar Jun 23 '25 18:06 sfc-gh-alisowski

theres a good example for it here for anyone doing the migration: https://github.com/sst/sst/tree/dev/examples/aws-tanstack-start-vite

JonasRothmann avatar Jul 12 '25 16:07 JonasRothmann

Hey, I also had this issue after the recent update. The examples in SST didn't help, at least for me; the separate nitro config does not seem to connect to Vite.

This worked:

  1. npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5215
  2. add this config:
import { defineConfig } from "vite";
import tsConfigPaths from "vite-tsconfig-paths";
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import viteReact from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { livestoreDevtoolsPlugin } from "@livestore/devtools-vite";
import { nitroV2Plugin } from "@tanstack/nitro-v2-vite-plugin";

export default defineConfig({
  server: {
    port: 3000,
    allowedHosts: [
      process.env.MONOLITH_URL_PROXY?.replace(/^https?:\/\//, "")!,
    ],
  },
  css: {
    devSourcemap: true,
  },
  plugins: [
    tsConfigPaths(),
    tailwindcss(),
    tanstackStart(),
    nitroV2Plugin({
      preset: "aws-lambda",
      compatibilityDate: "2025-09-25",
    }),
    viteReact(),
    livestoreDevtoolsPlugin({ schemaPath: "./src/lib/sync-engine/schema.ts" }),
  ],
});

seems like the nitroV2Plugin solves the issue for now. I wanted to use the Nitro v3 plugin, but I couldn't find a way to import it.

if anyone manages to make it work let me know.

railaru avatar Sep 25 '25 07:09 railaru

nitro config goes into the nitro vite plugin now.

https://tanstack.com/start/latest/docs/framework/react/hosting#using-nitro-v2

schiller-manuel avatar Sep 28 '25 21:09 schiller-manuel

That's now a 404 @schiller-manuel

wilfredjonathanjames avatar Nov 20 '25 22:11 wilfredjonathanjames