0

I am using Redux Toolkit (v1.8) from the umd build, as I am using it inside a platform that does not enable package management integration.

I was trying to access RTK Query, but could not find a way to access it through the global exported by the umd script.

I was wondering if:

  1. I missed something and it's there, or
  2. It is necessary to use another script, or
  3. It is not possible to use RTK Query from the umd script

Thanks!

1 Answers1

0

There is a UMD build at https://unpkg.com/browse/@reduxjs/toolkit@1.8.0/dist/query/rtk-query.umd.js that will populate window.RTKQ.

Generally you should try to use the ESM build instead - most modern environments should be able to load that unbundled. Any kind of UMD build will probably be removed in RTK 2.0 - it is just not up to date to ship UMD any more.

Just out of curiosity: in what environment are you working? I cannot imagine anything that would work with only an UMD build.

phry
  • 35,762
  • 5
  • 67
  • 81
  • Thanks! I'm working in Salesforce (using Lightning Web Components). I would have been very happy to use the ESM build, but Salesforce doesn't really allow for a module/dependency system, and every external code has to be loaded statically from a single precompiled file. See: [Salesforce docs](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_third_party_library). If I'm missing something and it's still possible to use an ESM build without npm/yarn/etc. and have it as one precompiled file, I will be happy to learn about it! – Omri Kochavi Mar 06 '22 at 10:08
  • From looking at those docs I'm pretty sure every UMD build would fail their [Lightning Locker requirements](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_third_party_guidance) - every UMD build sets a `window.something` variable. I'm no expert on how to use that but I'm very sure you need to use an cjs or esm build from the start there. Maybe bundled manually locally using something like rollup. – phry Mar 06 '22 at 10:58