Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  92] [ 6]  / answers: 1 / hits: 25013  / 9 Years ago, sun, january 10, 2016, 12:00:00

In my previous Meteor app, using browserify, and React, all was working until I switched to meteor webpack.



I use react-select in my Meteor apps and it worked great but with browserify I could prevent multiple copies of react from loading which prevents this error I'm now having:




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).


My package.json look this:



...

dependencies: {
classnames: ^2.1.3,
lodash: ^3.10.0,
react: ^0.14.6,
react-dom: ^0.14.6,
react-mixin: ^2.0.1,
react-select: ^1.0.0-beta8
},

...


Is there a configuration in webpack I could use something call externals? Not fully sure what that means but a comment said to use:



externals: {
'react': 'React',
'react-dom': 'ReactDOM'
}

More From » meteor

 Answers
20

Since you use webpack, you can add an alias for loading react, like this:



// In webpack.config.js

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


This prevented the addComponentAsRefTo(...) error and made our build succeed again. However, for some reason, the testing build failed only on our CI environment as it could not resolve the node_modules/react path. I think it's unlikely that you will encounter this particular problem, though.


[#63781] Thursday, January 7, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tristab

Total Points: 735
Total Questions: 106
Total Answers: 96

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
tristab questions
Sat, Sep 25, 21, 00:00, 3 Years ago
Sun, Jan 31, 21, 00:00, 3 Years ago
Wed, Dec 2, 20, 00:00, 4 Years ago
Fri, Oct 23, 20, 00:00, 4 Years ago
;