#[Vercel] I can't seem to get the vercel deployment working

10 messages · Page 1 of 1 (latest)

dreamy herald
#

For this vite.config.ts i can't even serve locally the build. When i try to run it i get this:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/my-app/.output/server/server.js' imported from /my-app/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_rea_8f07dd2dc4f2e030cbea330a30ef30f3/node_modules/@tanstack/start-plugin-core/dist/esm/preview-server-plugin/plugin.js
    at finalizeResolution (node:internal/modules/esm/resolve:274:11)
    at moduleResolve (node:internal/modules/esm/resolve:864:10)
    at defaultResolve (node:internal/modules/esm/resolve:990:11)
    at nextResolve (node:internal/modules/esm/hooks:785:28)
    at o (file:///my-app/node_modules/.pnpm/@[email protected]/node_modules/@tailwindcss/node/dist/esm-cache.loader.mjs:1:69)
    at nextResolve (node:internal/modules/esm/hooks:785:28)
    at AsyncLoaderHooksOnLoaderHookWorker.resolve (node:internal/modules/esm/hooks:271:30)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:251:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:845:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)

Vite.config.ts will be in reply

i tried both nitro v3 and now with nitro v2 (had to remove some imports due to message being too long)

#
import { defineConfig } from 'vite';
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
import viteReact from '@vitejs/plugin-react';
import { nitroV2Plugin } from '@tanstack/nitro-v2-vite-plugin';

const config = defineConfig({
  build: {
    sourcemap: true,
    outDir: '.output',
    emptyOutDir: true,
    target: 'es2022',
    minify: true,
    rollupOptions: {
      treeshake: true,
      output: {
        manualChunks: (id: string) => {
          if (
            id.includes('phone/dist') ||
            id.includes('react-phone-number-input')
          ) {
            return 'phone';
          }

          if (id.includes('lodash')) {
            return 'lodash';
          }

          if (id.includes('country-flag-icons')) {
            return 'country-flag-icons';
          }

          if (id.includes('medusa')) {
            return 'medusa';
          }
        },
      },
    },
  },
  plugins: [
    // this is the plugin that enables path aliases
    viteTsConfigPaths({
      projects: ['./tsconfig.json'],
    }),
    tailwindcss(),
    tanstackStart(),
    nitroV2Plugin({
      preset: 'vercel',
      compatibilityDate: '2025-12-17',
      output: {
        dir: '.output',
      },
      routeRules: {
        // Cache fonts for 1 year (immutable)
        '/fonts/**': {
          headers: {
            'Cache-Control': 'public, max-age=31536000, immutable',
          },
        },
        // Cache images for 1 month
        '/**/*.{jpg,jpeg,png,gif,webp,svg,ico}': {
          headers: {
            'Cache-Control': 'public, max-age=2592000',
          },
        },
        // cache css
        '/**/*.{css}': {
          headers: {
            'Cache-Control': 'public, max-age=604800',
          },
        },
      },
    }),
    viteReact(),
  ],
  resolve: {
    alias: {
      '/fonts': '/public/fonts',
    },
  },
  ssr: {
    noExternal: ['@radix-ui/*', '@medusajs/*', 'nuqs'],
  },
});
noble ridge
#

there are some issues with vite preview and nitro at the moment

#

for now just start the server directly by invoking node .output/server/index.mjs

dreamy herald
#

Tnx for the suggestion, tried it but still doesn't work. I tried it both with v2 and v3 nitro.

🕙 11:53:24 ❯ pnpm serve                                      

> lov-ribolov-store@ serve /Users/josippapez/Desktop/lov-ribolov/lov-ribolov-store
> node .output/server/index.mjs

It just finishes running. Also, the default vercel output directory for server is functions so i even tried overriding that but still the same outcome

noble ridge
#

a full reproducer project would be helpful

#

cc @broken bronze

dreamy herald
#

Sure, just need to figure out where to host it, but right now i managed to reproduce it by creating a base project with pnpm create @tanstack/start@latest and adding tanstack query via the prompts with pnpm create. After that, i changed nitro() to

nitro({
      preset: 'vercel',
      output: {
        dir: '.output',
      },
    }),

and then i try to pnpm dev (works), pnpm build passes and then pnpm preview and node index.mjs directly, and the node one doesn't start while the preview returns the same error as above