T
TanStack3w ago
metropolitan-bronze

Global Middleware

Can someone help me pls, what the hell i am doing wrong -.-.
import { createMiddleware, createStart } from '@tanstack/react-start'
import { getRequest } from '@tanstack/react-start/server'

export const loggingMiddleware = createMiddleware().server(async ({ next }) => {
const request = getRequest()
console.log('request', request.url, crypto.randomUUID())
return next()
})

export const startInstance = createStart(() => {
return {
requestMiddleware: [loggingMiddleware],
}
})

data
:
message
:
"Cannot read properties of undefined (reading 'push')"
name
:
"TypeError"
stack
:
"TypeError: Cannot read properties of undefined (reading 'push')\n at hydrateStart (http://localhost:5055/node_modules/@tanstack/start-client-core/dist/esm/client/hydrateStart.js?t=1762376760469&v=83b5ef28:19:25)"
import { createMiddleware, createStart } from '@tanstack/react-start'
import { getRequest } from '@tanstack/react-start/server'

export const loggingMiddleware = createMiddleware().server(async ({ next }) => {
const request = getRequest()
console.log('request', request.url, crypto.randomUUID())
return next()
})

export const startInstance = createStart(() => {
return {
requestMiddleware: [loggingMiddleware],
}
})

data
:
message
:
"Cannot read properties of undefined (reading 'push')"
name
:
"TypeError"
stack
:
"TypeError: Cannot read properties of undefined (reading 'push')\n at hydrateStart (http://localhost:5055/node_modules/@tanstack/start-client-core/dist/esm/client/hydrateStart.js?t=1762376760469&v=83b5ef28:19:25)"
8 Replies
noble-gold
noble-gold3w ago
try changin requestMiddleware with functionMiddleware
fascinating-indigo
fascinating-indigo3w ago
please provide a complete reproducer project
metropolitan-bronze
metropolitan-bronzeOP3w ago
What do you mean by that its a fresh project with cli, and the sample from the docs -.-
ratty-blush
ratty-blush3w ago
This error only happens if you enable the middleware?
fascinating-indigo
fascinating-indigo3w ago
i cant reproduce this so please share a complete project
metropolitan-bronze
metropolitan-bronzeOP3w ago
Hey! Sorry for the late reply. It's really strange, I tested the whole thing again, created a new project with the CLI, and then the bug didn't occur. I've now pushed the project with the bug to GitHub, and the error is still there. https://github.com/CodingRuo/homestead_base
GitHub
GitHub - CodingRuo/homestead_base
Contribute to CodingRuo/homestead_base development by creating an account on GitHub.
metropolitan-bronze
metropolitan-bronzeOP3w ago
Yes!
fascinating-indigo
fascinating-indigo3w ago
please strip this down (remove the DB for example) so it can be cloned, installed and ran directly also upgrade to the latest version of start

Did you find this page helpful?