question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set property duplex of #<Request> which has only a getter

See original GitHub issue

Describe the bug

As of SvelteKit 1.0.0-next.406, I started getting this issue in server endpoints that used ky for making web reqeusts:

Cannot set property duplex of #<Request> which has only a getter

The issue stems from it setting request.duplex like this:

    const request = new Request('https://example.com')
    if (supportsRequestStreams) {
        // @ts-expect-error - Types are outdated.
        request.duplex = 'half';
    }

In SvelteKit 1.0.0-next.406, supportsRequestStreams started evaluating to true. It’s defined as this:

const supportsRequestStreams = (() => {
    let duplexAccessed = false;
    let hasContentType = false;
    const supportsReadableStream = typeof globalThis.ReadableStream === 'function';
    if (supportsReadableStream) {
        hasContentType = new globalThis.Request('https://a.com', {
            body: new globalThis.ReadableStream(),
            method: 'POST',
            // @ts-expect-error - Types are outdated.
            get duplex() {
                duplexAccessed = true;
                return 'half';
            },
        }).headers.has('Content-Type');
    }
    return duplexAccessed && !hasContentType;
})();

For context, setting request.duplex seems to be needed for compatibility with Chrome 105: https://github.com/sindresorhus/ky/commit/316fffe5ad9a1a1329816b6d82d02e7da05b6f35

I’m not sure entirely sure if this is an incorrect implementation in SvelteKit, or if the issue is with ky.

Ky issue: https://github.com/sindresorhus/ky/issues/467

Reproduction

https://github.com/probablykasper/sveltekit-fetch-duplex-bug

Logs

No response

System Info

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
    Memory: 820.51 MB / 32.00 GB
    Shell: 3.5.1 - /usr/local/bin/fish
  Binaries:
    Node: 16.15.0 - ~/Library/Caches/fnm_multishells/70304_1667344002694/bin/node
    Yarn: 1.22.15 - ~/Library/Caches/fnm_multishells/70304_1667344002694/bin/yarn
    npm: 8.12.1 - ~/Library/Caches/fnm_multishells/70304_1667344002694/bin/npm
  Browsers:
    Brave Browser: 97.1.34.81
    Chrome: 107.0.5304.87
    Firefox: 106.0.1
    Firefox Developer Edition: 107.0
    Safari: 15.6.1
  npmPackages:
    @sveltejs/adapter-auto: 1.0.0-next.86 => 1.0.0-next.86 
    @sveltejs/kit: 1.0.0-next.531 => 1.0.0-next.531 
    svelte: ^3.52.0 => 3.52.0 
    vite: ^3.2.2 => 3.2.2

Severity

serious, but I can work around it

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dummdidummcommented, Nov 4, 2022

Then this is on Ky’s end, because in the code that was linked they modify that property after initialising the request.

0reactions
vhscomcommented, Nov 11, 2022

For those who see this issue, ensure you’re passing duplex: 'half' into any fetch calls using RequestInit like:

const res = await fetch('/api/listing', {
  method: 'POST',
  // @ts-ignore-next-line - Types outdated
  duplex: 'half',
  body: JSON.stringify(theBody)
});

If helpful, pin undici using overrides in the package manifest. 5.12.0 is the Unidici version which introduces duplex.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Set Property ... Which Only Has Getter (javascript es6)
When a property is a getter/setter property, all references to the property go through the getter or setter, including from within the getter...
Read more >
Cannot set property of #<Object> which has only a getter #587
The specific reason this happens is because assigning a property to an object where the property already exists on the prototype chain will ......
Read more >
TypeError: setting getter-only property "x" - JavaScript | MDN
The JavaScript strict mode-only exception "setting getter-only property" occurs when there is an attempt to set a new value to a property for...
Read more >
Button Error on Pavlovia - TypeError: Cannot set property ...
Button Error on Pavlovia - TypeError: Cannot set property numClicks of [object Object] which has only a getter · OS · What are...
Read more >
Cannot set property material of [object Object] which has only ...
Cannot set property material of [object Object] which has only a getter ... I use AssetContainer.instantiateModelsToScene() clone the model.I need ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found