Skip to content

React alias for development with npm-link #393

Description

@michalwerner

Let's say we have app called My-app managed by create-react-app and some library My-lib, being dependency of My-app. Both uses React.
Now, using npm-link gives us multiple copies of React in dependency tree, which ultimately (at least for me) ends with this error:

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

The only solution I've found (http://stackoverflow.com/a/31170775/2395401) was to define alias in webpack configuration like this:

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

Of course this means ejecting project.
Isn't it good idea to place this alias in default config?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions