enzyme: Incorrect dependency version for React needed for React Native 0.43

React Native 0.43 has a peer dependency on React 16.0.0-alpha.6, but react-compat doesn’t check for major versions greater than 15.

This has the lovely effect of having the app compile and run successfully, but all the tests fail because it enzyme resolves to react@0.13-14.

It looks like this should be fairly straightforward. I could probably draft a PR tomorrow if need be.

Here’s the full error:

react-addons-test-utils is an implicit dependency in order to support react@0.13-14. Please add the appropriate version to your devDepen
dencies. See https://github.com/airbnb/enzyme#installation
/Users/haynesn/code/CrimsonConnect/node_modules/enzyme/build/react-compat.js:143
      throw e;
      ^

Error: Cannot find module 'react-addons-test-utils'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at /Users/haynesn/code/CrimsonConnect/node_modules/enzyme/build/react-compat.js:133:21
    at Object.<anonymous> (/Users/haynesn/code/CrimsonConnect/node_modules/enzyme/build/react-compat.js:219:5)

[snip]

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 18 (10 by maintainers)

Most upvoted comments

I think calling it “abuse” is a bit too much given that React team literally spends months of effort on things that don’t matter to Facebook but are significant to the open source community.

Yes, this particular case is unfortunate, and I’m open to suggestions on how we can make this better. What would you suggest we do instead?

This is a bug with react-native. An alpha should not be depended upon; and if it’s stable enough to depend upon, it shouldn’t be an alpha.

Please feel free to file a bug on react-native and/or react.

Issue is still there with latest and greatest RN releases 😦 With https://github.com/airbnb/enzyme/issues/893#issuecomment-301558517 and enzyme not supporting alpha’s we could be stuck for many months more. Like @andriichernenko … any advice?

Doesn’t seem like this issue is going to be resolved anytime soon. What do we do in the meantime? I am working on a new project which uses RN 0.44, so I don’t have any existing code which relies on enzyme. Should I downgrade to RN 0.42.3 or try to find some alternatives to enzyme (not even sure there are any)?

I guess I’d expect an RN that depends on a react alpha to be an alpha itself - npm maintains 2 versions at once (4, and 5 alpha), for example, so I don’t see why RN couldn’t do the same.

My impression is it just would not very practical, as it would effectively make all future releases of RN “alphas” for a few months even though they’re more stable than previous versions. React itself is such a tiny part of React Native (especially the react` package itself) that its version doesn’t reflect stability of RN itself. I understand this has ramifications for the community though.

Perhaps this is something you could discuss with @yungsters.

I agree that the error message is unhelpful; the best we could do to improve it is determine that you’re using React > 15, and throw immediately.

I entirely agree with pushing back against FB/React/RN’s confusing abuse of the “alpha” label—3rd party lib/tool support for RN in general is shockingly chaotic, and I think this cavalier attitude to release labeling and discipline is no small part of it—however they’ve shown no signs of changing their bizarre behavior, so it appears that any lib/tool that wishes to support RN ought to accept it or drop that support (publicly and as loudly as possible if you do, please). This ongoing clash of pushing-insane-release-labeling versus firmly-insisting-on-sane-release-labeling is just making life difficult for developers (users) of RN and related projects.

In short, Facebook’s entirely at fault for labeling their releases in a way that breaks convention, harms communication, erodes confidence/trust, and is generally and obviously poor practice for a bunch of good reasons, but having so many of the tools/libs that “support” RN always be several versions behind (and not always the same number of versions behind) RN stable really sucks for those of us trying to use it, regardless of whose fault it is.

That may be true, but that’s not how they manage compatibility between React and React Native. Depending on the alpha is intentional.

Still, it doesn’t change that enzyme incorrectly identifies react major versions > 15 as 0.13-0.14.

Alphas aren’t releases; enzyme doesn’t tend to support React alphas.

Since React 16 is only in alpha, React Native shouldn’t be requiring it in a non-alpha release.

The React team does amazing things, and I’m very glad Facebook and the React team are doing them - but that very statement, I think, represents the problem: that things being significant to the open source community don’t automatically make them matter to Facebook as a whole.


In this situation, I think the only path for now is to wait on #1007; after which, I hope both the React and React Native teams will ensure that any release includes an enzyme adapter that is compatible with it. I think that any other tooling that has issues will probably need to develop their own adapter pattern.