-
Notifications
You must be signed in to change notification settings - Fork 232
TypeError: Cannot read property 'createElement' of undefined #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm still confused as to what happened and why, but I assume you've raised this for others to find if they're in the same scenario (which is very kind of you) and there's nothing for me to actually do on this (let me know if I'm wrong about that). Closing. |
Yep it can be closed and I was just adding it for potentially anyone else since I found 0 topics on this problem. Jest allows you to override module resolution. By specifying
Inside
|
Oh, now I get it. Thanks for the explanation. Cc @testing-library/react about this, in case it ever comes up in your issues too. I think in this scenario they would resolve to themselves when trying to resolve I'm not sure how many other testing libraries also reference |
I doubt this issue will be very prevalent unless there’s somewhere out there suggesting to set a module resolution path to But sure anywhere under I didn’t dive further into the issue than what was necessary to fix it. |
So I encountered this problem again, it seems like a more robust fix is ensuring that root node_modules is used before any other node_modules
Would this be a correct assumption that it would solve the same issue? It is working for me and I have removed the other entry from Again not exactly related to react hooks but this is coming up in search results for others so thought it would be good to add. The issue surfaced again when I was testing using a symlinked dependency I was working against. I found the recommendation here: just-jeb/angular-builders#657 (comment) |
I would have though that goes against the desired behaviour of node module resolution where dependencies are nested when there are version conflicts. I'm by no means an expert on this issue or the configurations options being described here, so please correct me if I'm wrong, but perhaps |
Yeah I was actually thinking about this over the weekend and your comment is what I was thinking as well -- this would seem to go against the way module resolution is supposed to work. It should work but I'll verify tomorrow. |
Updated my comment, |
I just spent the better part of a day figuring out an issue we had, and while it is not an issue with this package per se, it had to do with a misconfigured jest config file and the fact that
@testing-library
namespace can also contain a package calledreact
. I would imagine this could happen anywhere that module resolution can be specified (jest, webpack, babel, tsconfig, etc.).Problem
When using both
@testing-library/react
and@testing-library/react-hooks
,renderHook
method throws an error:Actual problem
jest.config.js
was configured with the followingmoduleDirectories
:Suggested solution
Essentially what was happening before, when
renderHook
was called it would resolverequire('react')
to the closestreact
module, which ended up being@testing-library/react
.Another solution would be to explicitly define the react module, but this seems less correct.
This issue can be closed. Thank you.
The text was updated successfully, but these errors were encountered: