Skip to content

TypeError: Cannot read private member #state when using paraglideMiddleware with TanStack Start 1.145+ #573

Closed

Description

@iktakahiro

Description

When using paraglideMiddleware with TanStack Start 1.145.x, the following error occurs:

TypeError: Cannot read private member #state from an object whose class did not declare it
    at new Request (node:internal/deps/undici/undici:10426:27)
    at paraglideMiddleware (/path/to/src/paraglide/server.js:108:13)

Environment

  • @inlang/paraglide-js: 2.7.1
  • @tanstack/react-start: 1.145.3
  • Node.js: v22.x
  • Bun: 1.3.x

Setup

Strategy (no URL strategy):

--strategy cookie preferredLanguage baseLocale

server.ts:

import handler from '@tanstack/react-start/server-entry';
import { paraglideMiddleware } from './paraglide/server.js';

export default {
  fetch(req: Request): Promise<Response> {
    return paraglideMiddleware(req, ({ request }) => handler.fetch(request));
  },
};

Root Cause

The issue is in server.js line 108:

const newRequest = runtime.strategy.includes("url")
    ? new Request(runtime.deLocalizeUrl(request.url), request)
    : // need to create a new request object because some metaframeworks (nextjs!) throw otherwise
        // https://github.com/opral/inlang-paraglide-js/issues/411
        new Request(request);

TanStack Start 1.143+ refactored their middleware implementation (TanStack/router#5517) and now uses a custom Request object that is incompatible with Node's undici Request cloning via new Request(existingRequest).

When the url strategy is not used, the code tries to clone the request with new Request(request), which fails because undici's Request constructor cannot access the private #state field from TanStack's custom Request implementation.

Workaround

Modifying the generated server.js to skip cloning when url strategy is not used:

const newRequest = runtime.strategy.includes("url")
    ? new Request(runtime.deLocalizeUrl(request.url), request)
    : request;  // Don't clone, pass through directly

This works because when the URL strategy is not in use, there's no need to modify the request URL anyway.

Suggested Fix

Consider checking if cloning is actually necessary before attempting it. When the url strategy is not used, the original request can be passed through without modification.

Alternatively, a try-catch could be added to fall back to passing the original request if cloning fails.

Activity

  1. added a commit that references this issue on Jan 2, 2026
    b543516
  2. samuelstroschein commented on Jan 3, 2026

    @samuelstroschein
    Contributor

    @iktakahiro Is this bug unrelated to the fixed bug TanStack/router#6089?

    The workaround would break nextjs as the comment specifies why a new request is created even if URL is not used. Thus, I am hesitant to merge your workaround

    const newRequest = runtime.strategy.includes("url")
        ? new Request(runtime.deLocalizeUrl(request.url), request)
    -    : // need to create a new request object because some metaframeworks (nextjs!) throw otherwise
    -       // https://github.com/opral/inlang-paraglide-js/issues/411
            new Request(request);
  3. iktakahiro commented on Jan 4, 2026

    @iktakahiro
    ContributorAuthor

    @samuelstroschein These issues are related but distinct. Root cause is the same: Both stem from TanStack Start 1.143+ using custom Request wrappers (h3/srvx) with private fields (#state) that Node's undici Request constructor cannot access.
    However, they manifest differently:

    Where the fix should live: Technically, I believe this is a TanStack-side issue. Using new Request(existingRequest) is a standard Fetch API pattern for cloning requests, and custom Request implementations should be compatible with this usage.

    However, for better user experience, it makes sense for paraglide-js to also handle this defensively with a try-catch fallback.

    Of course, I respect your decision. As a TanStack Start user, I also add a comment in the TanStack Router repository if that would be more appropriate. (TanStack/router#6089 (comment))

  4. samuelstroschein commented on Jan 5, 2026

    @samuelstroschein
    Contributor

    @iktakahiro thanks for the detailed write up.

    I will test NextJS today if it still has the throwing behavior if the original request is passed through. If it doesn't, we could drop the clone approach.

    Alternatively, we can use request.clone() directly as it's also a standard web API https://developer.mozilla.org/en-US/docs/Web/API/Request/clone as per TanStack/router#6089 (comment) comment

  5. samuelstroschein commented on Jan 6, 2026

    @samuelstroschein
    Contributor

    The PR fixes the issue. Will merge it.

    Another issue opened up though: #576

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions