Search code examples
react-rails

Use react-rails with packages that have react as dependency


I've been playing with rails-react and it works great. Recently I added the react-dropzone library in my package.json.

I get the following error when I run npm install:

npm WARN EPEERINVALID [email protected] requires a peer of react@^0.14.0 but none was installed.

If I explicitly add react it installs everything just fine.

However when I go into the browser, I get the following error:

enter image description here

Using react-rails (1.5.0) and "react-dropzone": "^3.2.2"


Solution

  • I found a workaround in this post. Massive thanks to the author.

    The problem is the fact that both rails-react and the react-dropzone include react.

    So, instead we can remove the #= require react that comes from the gem and instead use the react library

    Other than some depreciation warning, everything else seem to work fine.

    In application.js, remove the #= require react and #= require react_ujs.

    In the components.js

    //= require_self
    //= require react_ujs
    
    React = require('react');
    

    In your components you can now require react var React = require('react');