TanStack / TanStack/router

`staticFunctionMiddleware` `Unexpected token '<', "<!DOCTYPE "... is not valid JSON `

Open
#7,630 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Router

Describe the bug

When I add staticFunctionMiddleware to my server function, it throws an error after the build:

Unexpected token '<', "<!DOCTYPE "... is not valid JSON

The returned object is serializable as JSON.

I also tried JSON.parse(JSON.stringify(result)), but I get the same error.

Complete minimal reproducer

https://github.com/aymericzip/staticFunctionMiddleware_repro

Steps to Reproduce the Bug
bun install 
bun run build
cd ./apps/website-tanstack
uncomment middleware in `apps/website-tanstack/src/serverFunctions/docs.ts`
bun run build
bun run start 

navigate to /doc

I also included a demo for https://github.com/TanStack/router/issues/7516
comment code in packages/@intlayer/design-system/src/providers/ReactQueryProvider.tsx

cd ../../
bun run build ## rebuild design system
cd ./apps/website-tanstack
bun run build
Expected behavior
Screenshots or Videos

Demo: https://drive.google.com/open?id=1gBbIZ2okGl099IfONT5lGjToc2TeMtBf&usp=drive_fs

Platform
"@tanstack/react-devtools": "0.10.5",
"@tanstack/react-query": "5.101.0",
"@tanstack/react-router": "1.170.15",
"@tanstack/react-router-ssr-query": "1.167.1",
"@tanstack/react-start": "1.168.25",
"@tanstack/react-virtual": "3.14.2",
"@tanstack/router-plugin": "1.168.18",
"bun": "1.3.14",

mac

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked minimal reproducer and run the listed Bun build/start steps. Then inspect apps/website-tanstack/src/serverFunctions/docs.ts and the referenced ReactQueryProvider.tsx setup while reproducing the failure at /doc. Done means the server function result loads without the unexpected JSON parse error after building.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, react, typescript
Domain
backend, build-system, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.