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

Alpha 2.0 - Cannot read properties of undefined (reading 'createApi') - Astro #3176

Closed
BorjaRafolsMartinez opened this issue Feb 14, 2023 · 4 comments
Milestone

Comments

@BorjaRafolsMartinez
Copy link

Just tried to setup RTK with Astro using the most basic setup.

It looks to me that the 2.0 Alpha version is still not generating valid ESM modules. This is way beyond my knowledge.
It's worth nothing that import the base query version works, just not the React one.

import query from '@reduxjs/toolkit/query'

[Module: null prototype] {
  QueryStatus: {
    uninitialized: 'uninitialized',
    pending: 'pending',
    fulfilled: 'fulfilled',
    rejected: 'rejected'
  },
  buildCreateApi: [Function: buildCreateApi],
  copyWithStructuralSharing: [Function: copyWithStructuralSharing],
  coreModule: [Function: coreModule],
  createApi: [Function: baseCreateApi],
  defaultSerializeQueryArgs: [Function: defaultSerializeQueryArgs],
  fakeBaseQuery: [Function: fakeBaseQuery],
  fetchBaseQuery: [Function: fetchBaseQuery],
  retry: [Function: retryWithBackoff] { fail: [Function: fail] },
  setupListeners: [Function: setupListeners],
  skipSelector: Symbol(RTKQ/skipToken),
  skipToken: Symbol(RTKQ/skipToken)
}

import query from '@reduxjs/toolkit/query/react'
undefined

I pushed it to a repo here: https://github.com/BorjaRafolsMartinez/astro-react-rtk

I believe this is part of what you want to achieve on 2.0. Let me know if I can help.

@markerikson
Copy link
Collaborator

@BorjaRafolsMartinez Well, the first issue is that import query isn't a valid way to use RTKQ :) We aren't trying to do a default export - it's all named exports.

What happens if you do import { createApi } from in both entry point names?

(although I'll agree it's odd that one entry point returns a default object and the other doesn't.)

@markerikson markerikson added this to the 2.0 milestone Feb 14, 2023
@BorjaRafolsMartinez
Copy link
Author

Sorry about that, I used default export for debugging purposes:
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query'
[Function: baseCreateApi]

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
error Cannot read properties of undefined (reading 'createApi')

@markerikson
Copy link
Collaborator

Hmm. That is extremely odd. Okay, I'll try to take a look when I have time. Thanks for reporting this and providing the repro!

@markerikson
Copy link
Collaborator

I'm going to assume this is fixed by the more recent alphas and betas, and close this.

Could you let us know for sure if it does or does not work, either way?

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