Have anybody meet the `addComponentAsRefTo(...): Only a ReactOwner can have refs` when using proxyquire with `React`
sheltonsuen opened this issue · comments
I am try to using proxyquire to mock a deep nested dependency using @global
like:
'src/shared/xxxComponent': {
default: fakeComponent,
'@global': true
}
But react log this error, I can't figure out what exactly reason this happen, Do you guys have any ideas about this? thanks a lot:)
full error log:
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).
at invariant (node_modules/fbjs/lib/invariant.js:44:15)
at Object.addComponentAsRefTo (node_modules/react-dom/lib/ReactOwner.js:68:68)
at attachRef (node_modules/react-dom/lib/ReactRef.js:23:16)
at Object.ReactRef.attachRefs (node_modules/react-dom/lib/ReactRef.js:42:5)
at ReactCompositeComponentWrapper.attachRefs (node_modules/react-dom/lib/ReactReconciler.js:23:12)
at CallbackQueue.notifyAll (node_modules/react-dom/lib/CallbackQueue.js:76:22)
at ReactReconcileTransaction.close (node_modules/react-dom/lib/ReactReconcileTransaction.js:80:26)
at ReactReconcileTransaction.closeAll (node_modules/react-dom/lib/Transaction.js:209:25)
at ReactReconcileTransaction.perform (node_modules/react-dom/lib/Transaction.js:156:16)
at batchedMountComponentIntoNode (node_modules/react-dom/lib/ReactMount.js:126:15)
at ReactDefaultBatchingStrategyTransaction.perform (node_modules/react-dom/lib/Transaction.js:143:20)
at Object.batchedUpdates (node_modules/react-dom/lib/ReactDefaultBatchingStrategy.js:62:26)
at Object.batchedUpdates (node_modules/react-dom/lib/ReactUpdates.js:97:27)
at Object._renderNewRootComponent (node_modules/react-dom/lib/ReactMount.js:319:18)
at Object._renderSubtreeIntoContainer (node_modules/react-dom/lib/ReactMount.js:401:32)
at Object.render (node_modules/react-dom/lib/ReactMount.js:422:23)
at Object.renderIntoDocument (node_modules/react-dom/lib/ReactTestUtils.js:91:21)
at renderWithOptions (node_modules/enzyme/build/react-compat.js:200:24)
at new ReactWrapper (node_modules/enzyme/build/ReactWrapper.js:94:59)
at mount (node_modules/enzyme/build/mount.js:19:10)
Hi there. Wish I could help but there's a lot of moving parts here and you haven't shared much code. Feel free to post more info but I can't guarantee we'll be able to help.
Thank you for this, I found another walk around way to solve this. For some security reason, I can't share the source code, but I can write a demo to demonstrate this situation later, I think maybe this is nothing about proxyquire
but enzyme
.
Anyway, thank you for your help, and proxyquire
is a pretty awesome tool.