TanStackT
TanStack11mo ago
9 replies
then-purple

500 error creating API route

Trying to create my first API route.

1. I added /app/api.ts
as noted here: https://tanstack.com/start/latest/docs/framework/react/api-routes#setting-up-the-entry-handler

2. ) I added /app/api/hello.ts with the example code:
import { createAPIFileRoute } from '@tanstack/react-start/api'

export const APIRoute = createAPIFileRoute('/api/hello')({
  GET: async ({ request }) => {
    return new Response('Hello, World! from ' + request.url)
  },
})


3. Then I restarted the dev server (a bunch of times) using "dev": "vinxi dev" as my
package.json
script.

500 error
[vite] Error when evaluating SSR module $vinxi/handler/api: failed to import "@tanstack/react-start/api"
|- Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './routes' is not defined by "exports" in /Users/me/myproj/node_modules/@tanstack/start-api-routes/node_modules/vinxi/package.json 
 
[unhandled] Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './routes' is not defined by "exports" in /Users/me/myproj/node_modules/@tanstack/start-api-routes/node_modules/vinxi/package.json imported from /Users/me/myproj/node_modules/@tanstack/start-api-routes/dist/esm/index.js
    at exportsNotFound (node:internal/modules/esm/resolve:314:10)
...


Suggestions?

Versions:
    "@tanstack/react-query": "^5.59.20",
    "@tanstack/react-router": "^1.82.1",
    "@tanstack/react-router-with-query": "^1.82.1",
    "@tanstack/react-start": "^1.114.22",
    "@tanstack/start": "^1.82.1",
API Routes are a powerful feature of TanStack Start that allow you to create server-side endpoints in your application without the need for a separate server. API Routes are useful for handling form s...
API Routes | TanStack Start React Docs
Was this page helpful?