isomorphic-style-loader icon indicating copy to clipboard operation
isomorphic-style-loader copied to clipboard

React should be a peer dependency, not a dependency

Open tstirrat15 opened this issue 6 years ago • 9 comments

This package only works in the context of a React application, but it doesn't require its own version of React.

Additionally, with recent changes to React's APIs (context, hooks), having multiple versions of React in an application can cause errors.

Moving React from a dependency to a peerDependency will address this.

tstirrat15 avatar Apr 24 '19 16:04 tstirrat15

More reading here: https://yarnpkg.com/blog/2018/04/18/dependencies-done-right/

tstirrat15 avatar Apr 24 '19 16:04 tstirrat15

I was brought here because after installing Webpack plugin duplicate-package-checker-webpack-plugin, I can see that the style loader is pulling in it's own version of React.

    WARNING in react
      Multiple versions of react found:
        16.8.4 ./~/isomorphic-style-loader/~/react
        16.8.6 ./~/react

samkelleher avatar May 05 '19 11:05 samkelleher

I just updated from react: 16.8.6 to react: 16.9.0 and I am now seeing the error due to using useStyle hook:

  Error: Invariant Violation: Invalid hook call. Hooks can only be called inside   of the body of a function component. This could happen for one of the followi  ng reasons:
  1. You might have mismatching versions of React and the renderer (such as Reac  t DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app

Will https://github.com/kriasoft/isomorphic-style-loader/pull/156 be merged any time soon?

MYKEU avatar Aug 15 '19 13:08 MYKEU

Any updates?

eseQ avatar Nov 14 '19 08:11 eseQ

Workaround

This error will happen after updating the version of React used in your application.

  1. Delete node_modules
  2. Delete yarn.lock
  3. Run yarn
  4. Verify by running yarn why react and seeing that only one version is referenced.

Your application will now run normally. All the versions of React are now consistent in your application.

samkelleher avatar Feb 03 '20 18:02 samkelleher

The workaround didn't work for me. Are there any updates?

dommangetnicolas avatar Apr 25 '20 17:04 dommangetnicolas

Nope. Check out the fork if you're still having problems. This library is pretty much dead.

tstirrat15 avatar Apr 25 '20 23:04 tstirrat15

Check out the fork if you're still having problems. This library is pretty much dead.

Which fork?

scruffian avatar Jun 09 '21 09:06 scruffian

It might have been this one? It's been long enough since I've touched this that I don't remember.

tstirrat15 avatar Jun 09 '21 14:06 tstirrat15