Skip to content

Multiple Copies of react installed #8026

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

Closed
nitish24p opened this issue Oct 20, 2016 · 4 comments
Closed

Multiple Copies of react installed #8026

nitish24p opened this issue Oct 20, 2016 · 4 comments

Comments

@nitish24p
Copy link

I am using a few react components made by various libraries like material ui and i get this message

Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

on doing npm ls react i can see only one version of react installed. I am using gulp and browserify for my build process. Any idea how i can solve this?

@tutts
Copy link

tutts commented Oct 20, 2016

I've found this is common when modules have React as a dependency rather than a peerDependency in the npm package. If you're using webpack, I've got around this by creating an alias, perhaps you can do something similar in Gulp.

  resolve: {
    alias: { 'react': path.resolve(__dirname, 'node_modules', 'react') }
  }

@nitish24p
Copy link
Author

Awesome that helped.. Just sharing some ref for others
https://www.npmjs.com/package/gulp-resolve-dependencies

Thanks.

@aweary aweary closed this as completed Oct 20, 2016
@gaearon
Copy link
Collaborator

gaearon commented Oct 21, 2016

Also please file issues in such libraries and gently ask them to use peerDependencies for react instead 😉 .

@nitish24p
Copy link
Author

For those who do not want to install any other packages for resolving. Configure a require key in the browserify object and that will take care of the error

browserify({
        entries: path,
        require: ['react', 'react-dom'] // <- this bit here
    })
    .on("error", function(err) {
      this.emit('end');
    })
    .transform("babelify", {presets: ["es2015", "react"]})
    .bundle()
    .pipe(source(fileName))
    .pipe(buffer())
    .pipe(gulpif(params.env === 'prod', uglify()))
    .pipe(gulp.dest('./web/build/js'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants