sveltekit TypeError: immutable

Viewed 32

I'm using sveltekit 1.0.0-next.483 running with npm run dev -- --host connecting to an endpoint with a mobile device i get this error:

typeError: immutable
    at Headers.append ([..]node_modules/undici/lib/fetch/headers.js:227:13)

This error only occurs on mobile device, connecting to the local net ip address.

my endpoint: src/routes/gqlendpoint/+server.ts

const base = 'http://localhost:4000/graphql';

export async function POST( opts: { request: Request} ): Promise<Response> {
    
    const { request } = opts;

    const body =  await request.json(); 

    const response = await fetch(base, {
        
        //credentials:"include",

        method: 'POST',
        
        headers: { 'Content-Type': 'application/json' },
        
        body: JSON.stringify(body)
    
    });

    return response;
}

the only way I found to unlock this situation, is by commenting a line of code inside node_modules/undici/lib/fetch/headers.js

// 3. If headers’s guard is "immutable", then throw a TypeError.
// 4. Otherwise, if headers’s guard is "request" and name is a
//    forbidden header name, return.
// Note: undici does not implement forbidden header names
if (this[kGuard] === 'immutable') {
  **//throw new TypeError('immutable')**
} else if (this[kGuard] === 'request-no-cors') {
  // 5. Otherwise, if headers’s guard is "request-no-cors":
  // TODO
}

which is certainly not a good solution.

0 Answers
Related