Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in production: "Uncaught TypeError: i.fetchBaseQuery is not a function" #3533

Closed
louh opened this issue Jun 18, 2023 · 5 comments
Closed

Comments

@louh
Copy link

louh commented Jun 18, 2023

I have a very basic implementation of RTK Query that follows the "Basic Usage" instructions exactly:

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'

export const myApi = createApi({
  reducerPath: 'myApi',
  baseQuery: fetchBaseQuery({
    baseUrl: '/api/v1/'
  }),
  endpoints: (builder) => ({
    getUser: builder.query({
      query: (userId) => `users/${userId}`
    })
  })
})

export const { useGetUserQuery } = myApi

It works exactly as expected in development, but when I deployed to a production instance, the app crashes, with this error in the console:

Uncaught TypeError: i.fetchBaseQuery is not a function

Am I to gather from this error message that RTK Query didn't bundle properly? I am using Parcel.

@markerikson
Copy link
Collaborator

Presumably, yeah, which is really bizarre. Never seen anyone report a problem like that before.

@louh
Copy link
Author

louh commented Jun 18, 2023

I was able to search issues for a few other related keywords and found a couple situations that seem similar to mine. Both users are using Parcel, like me.

#2584
#2899

I am trying their recommendations now.

@louh
Copy link
Author

louh commented Jun 18, 2023

I see the issue has been filed at Parcel as well: parcel-bundler/parcel#7622 (comment)

@louh
Copy link
Author

louh commented Jun 18, 2023

OK, it seems these previous comments tracked down the solution. In case anyone else has stumbled across this same error, the issue is that Parcel is somehow skipping aliased exports in RTK Query. The solution is to write the import from two separate packages instead, like this:

import { createApi } from '@reduxjs/toolkit/query/react'
import { fetchBaseQuery } from '@reduxjs/toolkit/query'

@markerikson Thanks for chiming in so quickly. I'll let you decide what to do with the issue, but my situation is resolved.

@markerikson
Copy link
Collaborator

Wow, that's screwy :(

Thanks for the heads-up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants