Skip to content

RTKQ: fetchFn using cross-fetch fails #1271

Closed
@RileyMShea

Description

@RileyMShea

When using fetchFn from createApi, isomorphic-fetch works but cross-fetch fails.

Both seem to run fine in react without RTKQ. But with cross-fetch+RTKQ, a request that should be:
/some-endpoint
is run in the browser as /[object%20Request].

Possible I'm an idiot and flubbing the cross-fetch import and that's the problem, but I've tried a few
different import/require default/destructured variations and none seem to solve the issue.

...
const { fetch } = require("cross-fetch");  // doesn't work
// const fetch = require("isomorphic-fetch");  // works

// Define a service using a base URL and expected endpoints
export const pokemonApi = createApi({
  reducerPath: "pokemonApi",
  baseQuery: fetchBaseQuery({
    baseUrl: "https://pokeapi.co/api/v2/",
    fetchFn: fetch,
  }),
...

Minimal Codesandbox example

https://codesandbox.io/s/vibrant-resonance-cvf7m?file=/src/services/pokemon.ts

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