Lock: [Version 10] Invariant Violation with React and Webpack

Created on 14 Apr 2016  路  9Comments  路  Source: auth0/lock

My application is targeting react v15.0.1 and auth0-lock v10. Everything's being bundled together by Webpack.

import Auth0Lock from 'auth0-lock/lib/classic';
let lock = new Auth0Lock('id', 'domain');

lock.show() throws the following:

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

I haven't dug too far into this, but it seems that the version of react auth0-lock is targeting (0.14.5) is conflicting with the version my application is targeting (15.0.1). I've worked around this by adding the follwoing to my webpack.config.js file:

resolve: {
  alias: {
    "react": __dirname + '/node_modules/react',
  }
}

So now, instead of Webpack bundling 2 versions of React (the version auth0-lock is targeting and the version my application is targeting), it's only bundling the version my app is targeting, and it tells anything else that requires React to look no further than that version.

Although things are working fine right now, I can see problems creeping up in the future. Is anyone aware of a better way to do this using Webpack?

bug v10

All 9 comments

We have updated the React dependency and we are less strict about its version. Thanks.

I still get this error on 10.3.0 - the only way to fix it was using @bbar's solution above

I still get this error on 10.7.3.

Still getting this on 10.14.0.

Seems like this is still an issue. @gnandretta can we reopen this?

how are you importing lock?

import Auth0Lock from 'auth0-lock'

I'm using TypeScript with ts-loader.

Thanks for your help @luisrudge

Can you provide a sample project?

@luisrudge I ran into the same issue. Here's a sample project using an ejected version of create-react-app:

https://github.com/samcorcos/auth0-invariant-violation

The only thing I changed was the place that React and ReactDOM are recognized. I'm no longer using the react package, but the CDN here and the webpack config here

Instructions

Add valid public keys here

$ yarn
$ npm start

Click on the button in the top right to log in.

The page won't responsively update on successful login (because I'm lazy), but you will see the error logged to the console and the login will fail.

Let me know if you need any more information.

Btw, it works with the non-CDN version of React.

@samcorcos it's because of the react-addons-css-transition-group package. It imports react/lib/ReactCSSTransitionGroup, so you have to alias that as well.
image

This might get fixed once we fix https://github.com/auth0/lock/issues/994

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adamtay picture adamtay  路  8Comments

benmadany picture benmadany  路  4Comments

DavidWells picture DavidWells  路  5Comments

maxlapides picture maxlapides  路  5Comments

fernandomunizz89 picture fernandomunizz89  路  3Comments