reduxjs / react-redux

Official React bindings for Redux
https://react-redux.js.org
MIT License
23.39k stars 3.36k forks source link

can't use react-redux with ink #1457

Closed mprast closed 5 years ago

mprast commented 5 years ago

Do you want to request a feature or report a bug? report a bug (If this is a usage question, please do not post it here—post it on Stack Overflow instead. If this is not a “feature” or a “bug”, or the phrase “How do I...?” applies, then it's probably a usage question.)

What is the current behavior? I'm trying to use react-redux with ink and yarn v2. When I attempt to import Provider I'm met with the following:


Error: A package is trying to access another package without the second one being listed as a dependency of the first one

Required package: react-dom (via "react-dom")
Required by: react-redux@virtual:3acb2abc1dfd4a22564c3a11c8c371d7f85acb8e75efb297111ee893174e7ed007fb72514c7f7294775b8562215f979c751a99c9108a7c4c8e007fc4f67cd244#npm:7.1.3 (via /src/atlas/.yarn/virtual/react-redux-virtual-638efc0d6c/3/root/.yarn/berry/cache/react-redux-npm-7.1.3-f0c157eca3.zip/node_modules/react-redux/lib/utils/reactBatchedUpdates.js)

    at Object.makeError (/src/atlas/.pnp.js:13858:26)
    at resolveToUnqualified (/src/atlas/.pnp.js:16265:43)
    at resolveRequest (/src/atlas/.pnp.js:16311:31)
    at Object.resolveRequest.maybeLog [as resolveRequest] (/src/atlas/.pnp.js:16350:32)
    at Function.module_1.default._resolveFilename (/src/atlas/.pnp.js:15781:37)
    at Function.module_1.default._load (/src/atlas/.pnp.js:15702:45)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/src/atlas/.yarn/virtual/react-redux-virtual-638efc0d6c/3/root/.yarn/berry/cache/react-redux-npm-7.1.3-f0c157eca3.zip/node_modules/react-redux/lib/utils/reactBatchedUpdates.js:6:17)
    at Module._compile (internal/modules/cjs/loader.js:776:30)

I'm guessing it's because react-redux is trying to do a static import here: https://github.com/reduxjs/react-redux/blob/5e6205a2f9bb18e1f8b0163382bc29230ea7d3d3/src/index.js#L11

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to a CodeSandbox (https://codesandbox.io/s/new) or RN Snack (https://snack.expo.io/) example below:

demo: https://codesandbox.io/s/festive-leftpad-cjr2w

What is the expected behavior? I'm expecting to be able to use Redux without react-dom or react-native, since the impression I got from the docs is that react-redux doesn't or shouldn't have hard dependencies on a particular rendering library (if I'm mistaken and didn't miss something obvious it might be a good idea to add a disclaimer to the README!)

For now I can add react-dom as an easy workaround, but it'd be nice not to have the extra dependency just so I can import Provider and connect

Which versions of React, ReactDOM/React Native, Redux, and React Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React Redux? React: 16.11.0 ReactDOM/React Native: N/A ink: 2.5.0 Redux: 4.0.4 React Redux: 7.1.3

markerikson commented 5 years ago

We do have a sort-of hard dependency on either react-dom or react-native, due to our need to use the unstable_batchedUpdates API they both export.

For other renderers, you'll need to use the "react-redux/alternate-renderers" entry point. It looks like we don't have that formally listed in the documentation atm, but you can see a description in the v7 release notes:

https://github.com/reduxjs/react-redux/releases/tag/v7.0.1

timdorr commented 5 years ago

Closing to track in #1458

mprast commented 5 years ago

oh, 'alternate-renderers' looks like what I needed. Thank you!

markerikson commented 5 years ago

@mprast sure! Please let us know if you have any issues using that - I'm not sure how many people have actually used it for real :) But, yeah, that's exactly why we added it.