Giter Site home page Giter Site logo

Comments (11)

yethee avatar yethee commented on July 28, 2024 2

I think the reason for the error is that an instance of Request is passed to fetch() as the second argument, instead of a plain object.

from openapi-typescript.

hauk88 avatar hauk88 commented on July 28, 2024 1

Hi. I ran into this while doing some testing of this lib. I have a small repo that reproduces the error:
https://github.com/hauk88/e2e-typesafe/tree/openapi-fetch-bug. The related code is in open-api/fe/src/App.tsx

It is not really refined and a bit hacked toghether with conda environments etc, so not the perfect repo to look at maybe, but I though I would leave it here anyway.

If you manage to run the backend (open-api/be/) and the frontend (open-api/fe/) it should reproduce the error in the console if you press the send button in the UI.
image

from openapi-typescript.

drwpow avatar drwpow commented on July 28, 2024

Edit: sorry; replied to wrong issue.

from openapi-typescript.

drwpow avatar drwpow commented on July 28, 2024

Could you provide a reproduction of this and give more information about what environment you’re fetching in (browser? node? deno?)? The tests are currently passing, and I’m not able to replicate it myself. I believe you’re having the issue, but not sure what hole our test suite has that needs to be filled.

from openapi-typescript.

cmcnicholas avatar cmcnicholas commented on July 28, 2024

Could you provide a reproduction of this and give more information about what environment you’re fetching in (browser? node? deno?)? The tests are currently passing, and I’m not able to replicate it myself. I believe you’re having the issue, but not sure what hole our test suite has that needs to be filled.

Hi, I don't have a repro currently but can look to put something together.

This is an NX monorepo with apps in a browser environment.

The only piece of middleware I have is:

{
    onRequest: (req) => {
      // add authentication
      req.headers.set('Authorization', `Bearer ${accessToken}`);

      // incorrectly sets headers for GET requests
      // https://github.com/drwpow/openapi-typescript/issues/1410
      if (req.method === 'GET' || req.method === 'DELETE') {
        req.headers.delete('Content-Type');
      }

      return req;
    },
  }

which after the update I have altered to this inline with the docs.

{
    onRequest: ({ request }) => {
      // add authentication
      request.headers.set('Authorization', `Bearer ${accessToken}`);

      // incorrectly sets headers for GET requests
      // https://github.com/drwpow/openapi-typescript/issues/1410
      if (request.method === 'GET' || request.method === 'DELETE') {
        request.headers.delete('Content-Type');
      }

      return request;
    },
  }

The rest is all pretty standard stuff:

const client = createClient<paths>({
  baseUrl,
});

await client.POST('/api/organisations/', { body: { name }, });

It never invokes a request and fails in the openapi-fetch library.

from openapi-typescript.

cmcnicholas avatar cmcnicholas commented on July 28, 2024

I've since put a breakpoint in the openapi-fetch.js implementation of coreFetch and traced this through to the invocation of fetch.

If I supplement the request variable with request.duplex = 'half' then it progresses and works as before. Has the creation of Request changed?

from openapi-typescript.

lukasbash avatar lukasbash commented on July 28, 2024

Same issue here. The weird part is that (at least in my case) it only happens when executing E2E tests with playwright and happy-dom. In the console trace of the now failing tests I find the same error:

TypeError: Failed to execute 'fetch' on 'Window': The `duplex` member must be specified for a request with a streaming body

from openapi-typescript.

benyaminbeyzaie avatar benyaminbeyzaie commented on July 28, 2024

I'm also facing this issue

from openapi-typescript.

drwpow avatar drwpow commented on July 28, 2024

Thank you all! Will push a fix to this later today. This also gives me enough info to see what needs to be added to the test suites to prevent this from happening again.

from openapi-typescript.

drwpow avatar drwpow commented on July 28, 2024

I think the reason for the error is that an instance of Request is passed to fetch() as the second argument, instead of a plain object.

Ah that’s it exactly. This change was to improve support for third-party custom fetchers, such as #1691, but it’s a flawed implementation and this currently doesn’t match the fetch spec. Will improve this handling so that it both matches the official fetch spec, and is also friendly to third-party fetch clients that aren’t technically spec-compliant but are close.

from openapi-typescript.

drwpow avatar drwpow commented on July 28, 2024

Also digging through other instances of this error, this seems to be an issue specific to Chrome/Chromium which made it difficult to catch 😅 (technically our tests run in Node.js, not Chromium). Safari has a different-but-related error, and in Firefox this Just Works™.

Anyway, wanted to dig further into the root issue before I understood the best fix to take (and I believe actual headless Playwright tests are the best thing to add here, rather than try and hack together Chrome and Safari tests in Node.js which are moving targets to say the least)

from openapi-typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.