Skip to content
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

React Hooks not working + single instance of React #15338

Closed
mwarger opened this issue Apr 5, 2019 · 6 comments
Closed

React Hooks not working + single instance of React #15338

mwarger opened this issue Apr 5, 2019 · 6 comments
Labels
Resolution: Stale Automatically closed due to inactivity

Comments

@mwarger
Copy link

mwarger commented Apr 5, 2019

I originally posted this in the hooks thread, but this appears to be a separate issue as none of the troubleshooting steps resolve it, and I appear to only have a single copy of React... help would be greatly appreciated - I have a simple reproduction linked below.

Issue:

I'm having an issue using a very basic reproduction using yarn workspaces example - https://github.com/mwarger/yarn-workspace-hooks-repro

I have a component-library that is written in typescript and bundled with parcel. The example-demo is what will showcase this component-library and is a freshly created CRA app. All common packages are hoisted with yarn, so in theory there should only be one version of react available. However, the React.useEffect call I'm making in index.tsx causes the error that leads me to this GitHub issue.

Everything works until a hook is added. To reproduce the error, uncomment lines 7-9 in component-library/src/index.tsx

Hopefully I'm doing something silly that I have overlooked. Please advise as to any steps I may use to try and remedy this. Thank you!

Follow-up Edit: The below suggested debug script output prints true for me. It appears that I do not have two Reacts.

// Add this in node_modules/react-dom/index.js
window.React1 = require('react');

// Add this in your component file
require('react-dom');
window.React2 = require('react');
console.log(window.React1 === window.React2);

Originally posted by @mwarger in #13991 (comment)

@dardino
Copy link

dardino commented Jun 28, 2019

I have the same problem

@dcecile
Copy link

dcecile commented Jul 5, 2019

React doesn't support yarn link (see #14257), and probably has the same issue with Yarn workspaces.

You'll have to get Parcel to flatten the React modules from both workspaces into a single module (i.e. like Webpack alias).

Or, maybe Yarn resolutions would work?

@uchami
Copy link

uchami commented Aug 1, 2019

same issue here. Yarn resolutions does not affect anything at all. And my app is created with create-react-app so I'm not able to change any webpack for adding aliases. Any ideas?

@stale
Copy link

stale bot commented Jan 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@stale
Copy link

stale bot commented Jan 17, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@stale stale bot closed this as completed Jan 17, 2020
@punisher21maximum
Copy link

facing same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

No branches or pull requests

5 participants