Skip to content
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

Component no longer runs after being installed as a node module #3320

Closed
gsklee opened this issue Mar 5, 2015 · 6 comments
Closed

Component no longer runs after being installed as a node module #3320

gsklee opened this issue Mar 5, 2015 · 6 comments

Comments

@gsklee
Copy link

gsklee commented Mar 5, 2015

I have a reusable component Chart which I decided to put it up on GitHub. The weird thing is, although it's the exact same file, it works flawlessly while being part of my original project:

import Chart from './chart';

...

render() {
  return <Chart />;
}

But it's not working at all once I pull it down as a node package:

import Chart from 'react-chartist-tooltip';

...

render() {
  return <Chart />;
}

The error given is Uncaught Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. This usually means that you're trying to add a ref to a component that doesn't have an owner (that is, was not created inside of another component'srendermethod). Try rendering this component inside of a new top-level component which will hold the ref. but I am not sure if I understand it. Is this intended behavior?

@zpao
Copy link
Member

zpao commented Mar 5, 2015

Seems odd… cc @spicyj @sebmarkbage

@doowb
Copy link

doowb commented Mar 5, 2015

One thing that I noticed is that you're using the minified file in your package.json:main property. Could this be causing the issue?

@gsklee
Copy link
Author

gsklee commented Mar 6, 2015

This is the weird part. If I copy-paste the content of either react-chartist-tooltip.js or react-chartist-tooltip.min.js into ./chart then everything is gonna be working. As soon as I switched to import the file (the minified one as @doowb has noticed) as a node package it gives the error.

@gsklee
Copy link
Author

gsklee commented Mar 6, 2015

I disabled uglification so react-chartist-tooltip.min.js is only being transpiled by Babel and it still gives the error.

The cause of the invariant violation is that the owner of addComponentAsRefTo: function(component, ref, owner) is null instead of a ReactCompositeComponentWrapper object which it should be.

@gsklee
Copy link
Author

gsklee commented Mar 6, 2015

Fixed this by specifying React as a peer dependency rather than a normal dependency in package.json. Two copies of React appeared in my compiled app and behaved differently, causing the error.

@jedwards1211
Copy link
Contributor

I had this issue but I think it was caused by a library expecting something as a commons chunk

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