-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
When trying to link an application using MUI v5, application gets "TypeError: Cannot read properties of null (reading 'useContext')" #42554
Comments
Code snippets alone won't help us debug the issue, as the pasted code might differ from your actual code. Please provide a minimal reproduction in a GitHub repository. You can create two separate repositories: one for your shared library and another for your React app. |
Here is the dummy app that uses the shared library: Here is a dummy shared library: Steps to repo:
Removing material from Error Notification component makes the error go away |
@MatTaNg I encountered the following error when running
Additionally, I noticed that |
I updated the ui-shared-library, it should be working now ^ Use the same repo steps as above I moved material into dependencies and installed @emotion/styled and @emotion/react |
I am still getting the same error as #42554 (comment) when I run |
I just cloned the ui-shared-repo and did a
Are you running these steps exactly? |
Yes. See screen recording: issue-42554.mp4 |
Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information. |
How was this problem solved? I am getting the same error message. |
Please provide proper reproductions. |
Not solved. There wasn't a reply to the above message so the issue got closed automatically.
Please provide proper reproductions. |
Steps to reproduce
Link to live example: (required)
Steps:
ErrorNotification
and index.ts code below and put it in a new projectErrorNotification
Current behavior
We are trying to use MUI in our shared library to create shared components for our applications. Our shared application is working fine when it is imported from artifactory and within the shared repo as well.
We have recently decided to locally link our shared repo with our application using
yarn link
however, we keep running into this error below in applications that use our shared library:I spun up a CRA and just linked the shared library to create a minimal environment
The only code I modified in the CRA is App.js, I have highlighted the modified code below:
This is simply to import a component in our shared library.
This is what
ErrorNotification
looks like in our shared repo:Then we export our
ErrorNotification
in src/index.tsHere is our package.json in our shared library:
We use rollup to create our dist folder:
rollup.config.mjs:
Once the environment is set up what we've been doing is in our shared repo we'd run:
yarn
rollup -c
npm unlink @xxxx/ui-shared-library
npm link
Then in the CRA app:
npm unlink @xxxx/ui-shared-library
npm link @xxxx/ui-shared-library
npm run start
Expected behavior
Applications should be able to successfully link to our shared repo for local development
Context
We are trying to link our shared repo with our application locally so changes are instantly reflected on our applications
Your environment
npx @mui/envinfo
Testing on Chrome v125.0.6422.77
Search keywords: useContext, Invalid hook call, npm link, yarn linkn
The text was updated successfully, but these errors were encountered: