How to prevent multiple copies of React from being loaded?


Sylar:

In my previous Meteor app, using browserify and React, everything worked until I switched to meteor webpack .

I'm using react-select in a Meteor app and it works great, but using browserify prevents multiple copies of react from being loaded, thus avoiding this error:

Error: Always violated: addComponentAsRefTo(...): Only ReactOwner can have a reference. You may be adding refs to components that are not created in the component's render method, or you may have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

My package.json looks like 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 that I can use external calls? It's not entirely clear what that means, but a comment:

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

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

// In webpack.config.js

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

This avoids addComponentAsRefTo(...)errors and makes our build successful again. However, for some reason the test build only fails in our CI environment because it cannot resolve the node_modules/reactpath. I don't think you're likely to encounter this particular problem.

Related


How to prevent multiple copies of React from being loaded?

Sylar: In my previous Meteor app, using browserify and React, everything worked until I switched to meteor webpack . I'm using react-select in a Meteor app and it works great, but using browserify prevents multiple copies of react from being loaded, thus avoid

How to prevent multiple copies of React from being loaded?

Syrah In my previous Meteor app, using browserify and React, everything worked fine until I switched to meteor webpack . I'm using react-select in a Meteor app and it works great, but using browserify prevents multiple copies of react from being loaded, thus a

How to prevent multiple copies of React from being loaded?

Sylar: In my previous Meteor app, using browserify and React, everything worked until I switched to meteor webpack . I'm using react-select in a Meteor app and it works great, but using browserify prevents multiple copies of react from being loaded, thus avoid

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile inside the specfolder I want to use with RSpec . However, this file is loaded every time

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that lives in the specfolder I want to use with RSpec . However, this file is loaded eve

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that lives in the specfolder I want to use with RSpec . However, this file is loaded eve

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that is inside the folder I want to specuse with RSpec . However, this file is loaded ev

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that is inside the folder I want to specuse with RSpec . However, this file is loaded ev

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that is inside the folder I want to specuse with RSpec . However, this file is loaded ev

How to prevent a specific dynamic library from being loaded

Herman I want to use an ancient software (Unreal Tournament "Classic" from 1999, also known as UT99). The dynamic library libtxc_dxtn.sois loaded implicitly in search of optional S3 Texture Compression (S3TC) support. Unfortunately, when loading the library, t

How to prevent data from being loaded in NgRx a second time?

Irina I have a DOM block: <div (click)="toggle(block)"> <div *ngIf="block.opened"> <div *ngFor="let item of block.items"></div> </div> </div> On click I dispatch action to load data from server and display this data in block: toggle(block: Regist

How to prevent a specific dynamic library from being loaded

Herman I want to use an ancient software (Unreal Tournament "Classic" from 1999, also known as UT99). The dynamic library libtxc_dxtn.sois loaded implicitly in search of optional S3 Texture Compression (S3TC) support. Unfortunately, when loading the library, t

How to prevent data from being loaded in NgRx a second time?

Irina I have a DOM block: <div (click)="toggle(block)"> <div *ngIf="block.opened"> <div *ngFor="let item of block.items"></div> </div> </div> On click I dispatch action to load data from server and display this data in block: toggle(block: Regist

How to prevent a specific dynamic library from being loaded

Herman I want to use an ancient software (Unreal Tournament "Classic" from 1999, also known as UT99). The dynamic library libtxc_dxtn.sois loaded implicitly in search of optional S3 Texture Compression (S3TC) support. Unfortunately, when loading the library, t

How to prevent a specific dynamic library from being loaded

Herman I want to use an ancient software (Unreal Tournament "Classic" from 1999, also known as UT99). The dynamic library libtxc_dxtn.sois loaded implicitly in search of optional S3 Texture Compression (S3TC) support. Unfortunately, when loading the library, t

How to prevent data from being loaded in NgRx a second time?

Irina I have a DOM block: <div (click)="toggle(block)"> <div *ngIf="block.opened"> <div *ngFor="let item of block.items"></div> </div> </div> On click I dispatch action to load data from server and display this data in block: toggle(block: Regist

How to prevent data from being loaded in NgRx a second time?

Irina I have a DOM block: <div (click)="toggle(block)"> <div *ngIf="block.opened"> <div *ngFor="let item of block.items"></div> </div> </div> On click I dispatch action to load data from server and display this data in block: toggle(block: Regist

Prevent method from being called multiple times in React JS

Rexroth I'm experimenting with reactjs multifield components by implementing Thinking in React , but can't figure out why the method in the child is being called multiple times here. var i = 0; class SearchBar extends Component { constructor(props) { sup

How to prevent multiple controls from being clicked quickly?

Jane Niplass I'm facing an issue to prevent a quick multi-control on click in a Xamarin.Forms PCL project on Android. Basically, I need to address the following four situations: Click button and back button in NavigationBar Click button and hardware back butto