TanStackT
TanStack4mo ago
2 replies
broad-salmon

Weird error when defining server route outside of /routes folder

I have a server route created in

// src/routes/api/orders/index.ts
import { createOrderApi } from "@/server/orders/api"

export const Route = createOrderApi


and here's the api implementation (simplified)
// src/server/orders/api.ts
export const createOrderApi = createFileRoute('/api/orders')({
  server: {
    handlers: ({ createHandlers }) =>
      createHandlers({
        POST: {
          middleware: [loggerMiddleware],
          handler: async ({ request }) => {
            return new Response('Hello, World! from ' + request.url)
          },
        },
      }),
  },
})


And then I would get this error in the browser
Crawling result not available
    at LoadPluginContext.handler (file:///Users/akmal/dev/codes/tstart-test/node_modules/.pnpm/@tanstack+start-plugin-core@1.133.2_@tanstack+react-router@1.132.47_react-dom@19.2.0_re_44f3203cbcacdbedcf4ef7c42e5b9d49/node_modules/@tanstack/start-plugin-core/dist/esm/start-router-plugin/plugin.js:139:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async EnvironmentPluginContainer.load (file:///Users/akmal/dev/codes/tstart-test/node_modules/.pnpm/vite@7.1.9_@types+node@22.18.8_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6/node_modules/vite/dist/node/chunks/dep-Chhhsdoe.js:30980:19)
    at async loadAndTransform (file:///Users/akmal/dev/codes/tstart-test/node_modules/.pnpm/vite@7.1.9_@types+node@22.18.8_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6/node_modules/vite/dist/node/chunks/dep-Chhhsdoe.js:26101:21)
    at async viteTransformMiddleware (file:///Users/akmal/dev/codes/tstart-test/node_modules/.pnpm/vite@7.1.9_@types+node@22.18.8_jiti@2.6.1_lightningcss@1.30.1_tsx@4.20.6/node_modules/vite/dist/node/chunks/dep-Chhhsdoe.js:27221:20)


Works fine when I move the api implementation back to src/routes/api/orders/index.ts

Not sure if this is expected
Was this page helpful?