Tanstack start: Cannot find package 'nitro'
oakylabs
FREEOP

3 months ago

Hey there! I am trying to deploy a tanstack start application (within a monorepo) and i followed the tanstack-start logic with":

"nitro": "npm:nitro-nightly@latest"

and it says cannot find package nitro. any idea of why this is happening?

$20 Bounty

37 Replies

oakylabs
FREEOP

3 months ago

Tanstack start: Cannot find package 'nitro'


oakylabs
FREEOP

3 months ago

I already linked the service. but odnt know what is happening


lu4p
FREE

3 months ago

Did you import it as import { nitro } from 'nitro/vite'

Not just nitro


oakylabs
FREEOP

3 months ago

import { defineConfig } from "vite";
import { devtools } from "@tanstack/devtools-vite";
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import viteReact from "@vitejs/plugin-react";
import viteTsConfigPaths from "vite-tsconfig-paths";
import { fileURLToPath, URL } from "node:url";
import devtoolsJson from "vite-plugin-devtools-json";
import tailwindcss from "@tailwindcss/vite";
import { nitro } from "nitro/vite";

const config = defineConfig({
  envDir: "../../",
  resolve: {
    alias: {
      "~": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  ssr: {
    external: ["pg", "pg-native"],
    noExternal: [],
  },
  plugins: [
    devtools(),
    // @ts-expect-error dont know why
    nitro(),
    // this is the plugin that enables path aliases
    viteTsConfigPaths({
      projects: ["./tsconfig.json"],
    }),
    tailwindcss(),
    tanstackStart(),
    viteReact(),
    devtoolsJson(),
  ],
});

export default config;

this is my vite config


lu4p
FREE

3 months ago

Can you also share your package.json


oakylabs
FREEOP

3 months ago

of course 🙂

{
  "name": "@imoexclusivo/frontend",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "bun --bun --env-file ../../.env vite dev --port 3000",
    "build": "vite build",
    "preview": "vite preview",
    "test": "vitest run",
    "start": "node .output/server/index.mjs",
    "check": "tsc --noEmit"
  },
  "dependencies": {
    "@better-auth/stripe": "^1.4.18",
    "@hookform/resolvers": "^5.2.2",
    "@imoexclusivo/db": "workspace:*",
    "@imoexclusivo/shared": "workspace:*",
    "@imoexclusivo/queues": "workspace:*",
    "@marsidev/react-turnstile": "^1.4.1",
    "@radix-ui/react-accordion": "^1.2.12",
    "@radix-ui/react-alert-dialog": "^1.1.15",
    "@radix-ui/react-aspect-ratio": "^1.1.7",
    "@radix-ui/react-avatar": "^1.1.10",
    "@radix-ui/react-checkbox": "^1.3.3",
    "@radix-ui/react-collapsible": "^1.1.12",
    "@radix-ui/react-context-menu": "^2.2.16",
    "@radix-ui/react-dialog": "^1.1.15",
    "@radix-ui/react-dropdown-menu": "^2.1.16",
    "@radix-ui/react-hover-card": "^1.1.15",
    "@radix-ui/react-label": "^2.1.7",
    "@radix-ui/react-menubar": "^1.1.16",
    "@radix-ui/react-navigation-menu": "^1.2.14",
    "@radix-ui/react-popover": "^1.1.15",
    "@radix-ui/react-progress": "^1.1.7",
    "@radix-ui/react-radio-group": "^1.3.8",
    "@radix-ui/react-scroll-area": "^1.2.10",
    "@radix-ui/react-select": "^2.2.6",
    "@radix-ui/react-separator": "^1.1.7",
    "@radix-ui/react-slider": "^1.3.6",
    "@radix-ui/react-slot": "^1.2.4",
    "@radix-ui/react-switch": "^1.2.6",
    "@radix-ui/react-tabs": "^1.1.13",
    "@radix-ui/react-toggle": "^1.1.10",
    "@radix-ui/react-toggle-group": "^1.1.11",
    "@radix-ui/react-tooltip": "^1.2.8",
    "@tailwindcss/vite": "^4.1.18",
    "@tanstack/react-devtools": "^0.7.0",
    "@tanstack/react-query": "^5.90.20",
    "@tanstack/react-router": "^1.132.0",
    "@tanstack/react-router-devtools": "^1.132.0",
    "@tanstack/react-router-ssr-query": "^1.157.17",
    "@tanstack/react-start": "^1.132.0",
    "@tanstack/react-store": "^0.8.0",
    "@tanstack/react-table": "^8.21.3",
    "@tanstack/router-plugin": "^1.132.0",
    "better-auth": "^1.4.18",
    "better-auth-localization": "^2.2.3",
    "class-variance-authority": "^0.7.1",
    "clsx": "^2.1.1",
    "cmdk": "^1.1.1",
    "date-fns": "^4.1.0",
    "embla-carousel-react": "^8.6.0",
    "hono": "^4.11.9",
    "input-otp": "^1.4.2",
    "lucide-react": "^0.561.0",
    "next-themes": "^0.4.6",
    "nitro": "npm:nitro-nightly@latest",
    "posthog-js": "^1.336.4",
    "react": "^19.2.0",
    "react-day-picker": "^9.13.0",
    "react-dom": "^19.2.0",
    "react-hook-form": "^7.71.1",
    "react-intersection-observer": "^10.0.2",
    "react-resizable-panels": "^4.5.6",
    "recharts": "2.15.4",
    "sonner": "^2.0.7",
    "stripe": "^20.0.0",
    "tailwind-merge": "^3.0.2",
    "tailwindcss": "^4.1.18",
    "tw-animate-css": "^1.3.6",
    "use-debounce": "^10.1.0",
    "vaul": "^1.1.2",
    "vite-tsconfig-paths": "^6.0.2",
    "zod": "^4.3.6"
  },
  "devDependencies": {
    "@tanstack/devtools-vite": "^0.3.11",
    "@testing-library/dom": "^10.4.0",
    "@testing-library/react": "^16.2.0",
    "@types/node": "^22.10.2",
    "@types/react": "^19.2.0",
    "@types/react-dom": "^19.2.0",
    "@vitejs/plugin-react": "^5.0.4",
    "jsdom": "^27.0.0",
    "typescript": "^5.7.2",
    "vite": "^7.1.7",
    "vite-plugin-devtools-json": "^1.0.0",
    "vitest": "^3.0.5",
    "web-vitals": "^5.1.0"
  }
}

lu4p
FREE

3 months ago

Can you try if putting nitro under tanstackstart in your plugins helps?


lu4p
FREE

3 months ago

Can you also show the error you suppressed with // @ts-expect-error


asharibali
PRO

3 months ago

bro! it's simple:

The "Cannot find package 'nitro'" error happens because Railway's build runs in isolation if your service root is set to the app's sub-folder (e.g., /apps/web). This misses the monorepo's full dependency context, so the alias "nitro": "npm:nitro-nightly@latest" isn't resolved during Vite's import of { nitro } from "nitro/vite".

Fix

  1. In Railway service settings, change Root Directory to / (monorepo root).
  2. Set Build Command to: npm install && npm run build --filter=your-app-name (replace your-app-name with your app's package name, e.g., web; adjust for pnpm/yarn if used).
  3. Set Start Command to: node apps/your-app-name/.output/server/index.mjs (adjust path to match your structure).
  4. Redeploy.

Validation: Per Railway monorepo docs and TanStack Start hosting guide.


lu4p
FREE

3 months ago

tsconfig would also help


oakylabs
FREEOP

3 months ago

ts-expect error is not there anymore. removing in next commit

i will try @asharibali approach


oakylabs
FREEOP

3 months ago

root directory: check

build command bun install && bun run --filter=@imoexclusivo/frontend build: check

start command

bun run --filter=@imoexclusivo/frontend start is this not enough?


oakylabs
FREEOP

3 months ago

still getting the same error


lu4p
FREE

3 months ago

Can you share your app.config.ts


oakylabs
FREEOP

3 months ago

i dont have an app.config.ts


When using Bun as package manager in a monorepo, you need to make sure nitro package is properly hoisted.

bunfig.toml:

[install]

publicHoistPattern = ["nitro*"]

delete your node_module and lockfile then install again and commit the new changes.


oakylabs
FREEOP

3 months ago

that bunfig.toml... should it be at the root or where?


lu4p
FREE

3 months ago

Your start command should just be the build output sth like "./apps/web/.output/server/index.mjs"

Check locally where the file actually is


oakylabs
FREEOP

3 months ago

the opackage .json says its literally: ""node .output/server/index.mjs""


oakylabs

that bunfig.toml... should it be at the root or where?

Yes, at the root of your monorepo


oakylabs
FREEOP

3 months ago

ok testing now with your solution


oakylabs
FREEOP

3 months ago

nope./ same error after 15 seconds


oakylabs
FREEOP

3 months ago

removed bun.lock, removed node modules. do i need to remove all node modules and all bun locks? or the root ones should be ok?


The solution is from the Nitro docs, you can check it here: https://v3.nitro.build/docs/nightly


oakylabs

removed bun.lock, removed node modules. do i need to remove all node modules and all bun locks? or the root ones should be ok?

Yes, you should remove them all.


oakylabs
FREEOP

3 months ago

done that. still getting the same errors.


oakylabs
FREEOP

3 months ago

i really dont udnerstand. it sohuld be easy no?


oakylabs
FREEOP

3 months ago

i have tried nitro's approach and im getting cursor now complaining that

publicHoistPattern = ["nitro*"] is not acceptable


asharibali
PRO

3 months ago

Try this @oakylabs:

  1. Add/update bunfig.toml at monorepo root (fix syntax and force hoisting for simplicity): text
[install]  
linker = "hoisted"  # Hoists all deps to root, resolving isolation  
publicHoistPattern = [ "nitro*" ]  # Selective hoist for nitro (if hoisted doesn't work alone)  
  1. Remove all node_modules and bun.lockb (root + sub-folders), then run bun install locally to regenerate.
  2. In Railway settings:
    • Root Directory: / (monorepo root).
    • Build Command: bun install && bun --cwd apps/frontend run build (adjust apps/frontend to your exact sub-folder path, e.g., packages/frontend).
    • Start Command: node apps/frontend/.output/server/index.mjs (adjust path; uses Node runtime after Bun install).

and then see it fixes or not? let here.


oakylabs
FREEOP

3 months ago

trying now


oakylabs
FREEOP

3 months ago

still taking a snapshot


oakylabs
FREEOP

3 months ago

still same error


oakylabs
FREEOP

3 months ago

unrelated, i cant even haev service variables added to one of my services


oakylabs
FREEOP

3 months ago

Nothing is working 🙁


oakylabs
FREEOP

3 months ago

the moment i without notcing removed nitro it started working. trying again with nitro tho


therobotcarlson
PRO

3 months ago

👋 I have working tanstack start with nitro. in your vite config, do you have: nitro({ preset: "bun" }) ?


therobotcarlson
PRO

3 months ago

I have the above set, then start with:

bun run ./.output/server/index.mjs

per:

https://nitro.build/deploy/runtimes/bun


Welcome!

Sign in to your Railway account to join the conversation.

Loading...