When trying to link an application using MUI v5, application gets "TypeError: Cannot read properties of null (reading 'useContext')" #42554
Labels
package: material-ui
Specific to @mui/material
status: waiting for maintainer
These issues haven't been looked at yet by a maintainer
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: