-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
you have multiple copies of React loaded #2818
Comments
Happens while using DropDownMenus too. Removing node_modules_material-ui/node_modules/react helps avoid the error as well. |
@iceafish @neenaoffline Are you having this issue only on 0.14.1 and not 0.14.0? Can you show me which code is causing the error or what component it is complaining about? This might be related to #2802. If one of are able to try what's in |
I am facing the same error message in 0.14.2 with the Datepicker component (in node 4.2.3/npm 2.14.7). |
@mlarcher I tried writing a test Also you shouldn't need Maybe try deleting your |
I already tried deleting node_modules and reinstalling, with no luck.
Error seems to be on render (but I'm not utterly sure about that).
|
@mlarcher Thanks for copying the code. Could you try this as your import instead? import {DatePicker} from 'material-ui/lib/date-picker'; The Edit: Actually, your code should work. Let me look into this some more. |
@mlarcher I can't reproduce this. I'm not having a problem importing The biggest difference is I (or the docs) don't use browserify. Would you be able to put a sample reproducible example on github somewhere that I can clone and try? |
@mlarcher I'd recommend creating a project where your import React from 'react';
import ReactDOM from 'react-dom';
import DatePicker from 'material-ui/lib/date-picker/date-picker';
import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();
ReactDOM.render(
<DatePicker />,
document.getElementById('mainContainer')
); I did that in your project an am still having your problem. More specifically, the component renders, and this error logs to console when you click the component and the dialog appears:
I didn't identify the root cause, but I'm not able to reproduce this in my webpack based projects. I'm also not able to reproduce this in this project's browserify example. I'd probably look very closely at your build process to make sure that your not doing anything that could accidentally be bundling React multiple times. You may be able to find some help of StackOverflow with browserify as I'm not too familiar with it. Note: if you're going by the example, I just created #2857 so make sure to include those before running it. |
Hi everyone. I was having this problem with my own project, but I solved it. The problem is that "material-ui" 0.14.2 wants React "^0.14.6" but my project was using React 0.14.3, so When I upgraded my project to React 0.14.6, then reinstalled |
@crantila That's really weird. Why did npm install a copy for material-ui? React is a peer dependency for material-ui. npm doesn't automatically install peer dependencies. what version of npm are you using? |
@newoga There is indeed a problem with the way I generate the libs.js bundle. It may be due to the fact that the files in bundle.js are listed from the dependencies of my package.json, and even though 'material-ui' is an explicit dependency, 'material-ui/lib/date-picker/date-picker' isn't. Or maybe it is an issue with having react required by ES6 imports in my code and require() calls in meterial-ui. Anyhow, I'll have to find a better way to handle this kind of scenarios. Still, when I stop excluding libs from the bundling task and load all js from the same bundle, I don't have the invariant error anymore, but now the calendar opens but doesn't have any content : Edit: Actually, this problem is just due to the way the datepicker resizes when chrome dev tools is opened. No biggies, even though it could be improved. Problem is fixed for me, thanks for your help @newoga |
@alitaheri I'm using It seems like there are several different ways to cause multiple React versions to load, and they all result in |
Please, React should be removed from the dependencies of the lib. Check this excellent example of react-router React is used as a devDependency instead. Cheers for the good job you guys are doing! |
P.S. |
What do you mean? |
@oliviertassinari I had to remove react from within material-ui to get rid of "... or you have multiple copies of React loaded" |
*in my local dep tree |
With npm v3+ I never experienced this issue. Could you update your npm and try again? |
React is only a devDependency in material-ui as well, but that causes the https://github.com/npm/npm/blob/master/CHANGELOG.md On Tue, Jan 12, 2016 at 11:23 AM, Ali Taheri Moghaddar <
neena |
I was using npm 2 until recently and I had no issue. We declare react as a "dependency" at two places in our package.json. |
I removed node_modules and reinstalled, everything is ok now. |
@oliviertassinari
When I upgraded to npm v3, the issue was tackled by npm itself by keeping a single version of |
I am facing a similar problem with Meteor 1.3.beta4 and npm 2.14.14. I also tried with NPM3 but when I launch the app the console tells me that 'react' can't be found even if it is included with |
I have a project called ui that uses material-ui as base, then I import the ui to another project. The error happens to me when I import certains components to my ui project: When the size of the bundle increases like that, this error occurs. The same to this components: ListItem, MenuItem, IconButton... |
The issue for us is that we had shrinkwrapped 0.14.7 and material-ui 0.15-alpha-2 isn't shrinkwrapped so it pulled react 0.14.8. Would be nice if the deps were shrinkwrapped or more specific about versions. |
@mlarcher @ahmadferdous |
@haradakunihiko: this issue is related to npm-shrinkwrap, which is not involved on the problematic scenario, so I wonder if it could work in our case. I should give it a try, but for now we moved to npm3 to avoid the issue. Just to make it clear, our situation is the following: |
@mlarcher Actually, I'm definitely in the same situation, but with react-bootstrap. React-bootstrap has peer dependencies for react and it installs newer version of react inside react-bootstrap module. |
We were seeing these same issues while developing a common react components library that utilized Material UI. After trying many of the different solutions that were suggested, the following worked for us: Adding below to our webpack config:
Thanks to @mdarif for the tip! |
Making a alias solves my problem @cody-lettau @mdarif thanks anyways |
@felipethome I'm having the same problem, specifying react as an external resource to browserify did not fix the import of |
Got it! Thanks! |
@cody-lettau did you add that to the webpack config for the library, or for the project that uses that library? |
@sunny-g It was added to the library we were building. This library utilized material-ui. |
Thank you for the prompt response! I ended up using |
felipethome commented on 23 Feb |
My issue was a bit different. I had 2 different Webpack bundles and both were pulling in React. One of my NPM modules in the 2nd bundle did a I fixed it by adding the following to my 2nd bundle's Webpack config externals: {
// Don't bundle react or react-dom
'react': 'React',
'react-dom': 'ReactDOM',
} |
I had the same issue and i solved it by removing all the node modules and using yarn to install all the dependencies again. |
version 0.14.1 produces this error:
Uncaught Error: 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).If remove node_modules/material-ui/node_modules/react,the error isn't present.
The text was updated successfully, but these errors were encountered: