`staticFunctionMiddleware` `Unexpected token '<', "<!DOCTYPE "... is not valid JSON `
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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