-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Moved react-dom to dependencies #1261
Conversation
Deploy preview for react-redux-docs ready! Built with commit 1989033 |
Nope, it's not a direct dependency, because it can be used with React Native instead, or even without ReactDOM or React Native if you use the alternate entry point. |
@markerikson while that might be the case with manually using code from this repo, the npm installed package is dependent on Line 2 of the
Because of that Have a look at this example repo that I made to showcase the problem: |
No, that file is the UMD standalone build. It's only meant for use in web environments, and it's also not the file a bundler will pick up. Webpack and other bundlers will read index.js and pull in the ReactDOM batching. Metro, the RN bundler, will pull in the RN batching because of the .native.js extension. |
Why are jest and webpack then both throwing errors in this example repo of the problem: Dependencies:
|
@mikko-tormala : right. React-Redux does need ReactDOM, in a web environment. However, because React-Redux does not need ReactDOM in other environments, ReactDOM should not be a direct dependency. |
@markerikson Webpack will fail if Sure, The fact that one can use parts of this package without needing |
@mikko-tormala : simply put: React-Redux can be used in multiple environments. React Native is a valid alternate environment. In the RN environment, we do not rely on ReactDOM. Therefore, there is not a direct dependency. If anything, RD and RN are both peer deps, same as always. |
@markerikson If package 1 doesn't work in production without package 2, then package 1 is dependent on package 2. If there are any use cases where a package breaks in production because of a missing dependency, then that dependency should be added in. Saying it works for some users in some cases is not the right way to do dependency management. If a package breaks for some users, it should be treated as if it breaks for all users. I fixed this problem programmatically, but I shouldn't have to. |
Unfortunately, this is a limitation of the npm dependency system. What we actually have is a transient dependency on |
Yup. The closest we could do would be to declare both Realistically, anyone building a web app will have RD already installed (via a CRA project setup or otherwise), and anyone building an RN app will have RN already installed. So, everything just works fine as expected in those situations. It looks like the only reason you're running into any kind of an issue here is that A) you're using a lesser-known package manager that works differently, and B) you're running a command that (I assume) tries to recursively figure out what deps to install with a single call. And honestly, if you're building a web app, then you should able to add in ReactDOM yourself anyway as part of the app setup process. |
Saying it's a limitation of the npm dependency system is not really accurate, as this package is using it in a way that's not exactly kosher: There are arguably two different packages with different entry points and dependencies baked into one. I understand the hesitation to shift the Theoretically, the alternative would be to break the package into two separate packages going forward. One that requires Hypothetically, let's say |
A) This is correct and there's an easy solve I have in place for the problem I now have with it, but it doesn't change the fact that it's a dependency that is required by this package. |
With the inclusion of
{ unstable_batchedUpdates } from 'react-dom'
thereact-dom
package is now adependency
, as opposed to adevDependency
.Problem:
When installing with
pnpm recursive install
thereact-dom
package is not installed as a dependency for thereact-redux
package and builds using webpack will fail as the package is not available.Expected:
react-dom
should be a dependency.Workaround until fixed:
Using
pnpm hooks
(https://pnpm.js.org/docs/en/hooks.html), the followingpnpmfile.js
will fix the problem by moving the dependency programmatically: