Closed MatTaNg closed 1 week ago
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: https://github.com/MatTaNg/link-test
Here is a dummy shared library: https://github.com/MatTaNg/ui-shared-library
Steps to repo:
1) Run npm install on both repos
2) rollup -c && npm link
on ui-shared repo
3) npm link ui-shared-library on link-test repo
4) Run npm run start on link-test repo
5) Observe useContext error
Removing material from Error Notification component makes the error go away
@MatTaNg I encountered the following error when running rollup -c
in your ui-shared-library
:
[!] RollupError: node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.d.mts (38:12): Expected ',', got '*' (Note that you need plugins to import files that are not JavaScript)
node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.d.mts (38:12)
36: import { Platform } from '@floating-ui/dom';
37: import { platform } from '@floating-ui/dom';
38: import type * as React from 'react';
^
39: import { Rect } from '@floating-ui/dom';
40: import { ReferenceElement } from '@floating-ui/dom';
RollupError: Expected ',', got '*'
Additionally, I noticed that @mui/material
is listed as a dev dependency in your package.json. It should be installed as a regular dependency like @emotion/styled
. Also, @emotion/react
is missing from your shared library dependencies. See the installation docs.
I updated the ui-shared-library, it should be working now https://github.com/MatTaNg/ui-shared-library https://github.com/MatTaNg/link-test
^ 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 https://github.com/mui/material-ui/issues/42554#issuecomment-2198030215 when I run rollup -c
on ui-shared-library.
I just cloned the ui-shared-repo and did a rollup -c
and it worked for me. The exact steps I ran are:
1) git clone https://github.com/MatTaNg/ui-shared-library.git (cd into dir)
2) npm install
3) rollup -c
Are you running these steps exactly?
Are you running these steps exactly?
Yes. See screen recording:
https://github.com/mui/material-ui/assets/20900032/f445c6c3-ed9c-4118-a513-ab8fa89cc955
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.
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
``` System: OS: macOS 14.5 Binaries: Node: 18.14.2 - ~/.nvm/versions/node/v18.14.2/bin/node npm: 9.5.0 - ~/.nvm/versions/node/v18.14.2/bin/npm pnpm: Not Found Browsers: Chrome: Not Found Edge: Not Found Safari: 17.5 npmPackages: @emotion/react: 11.11.4 @emotion/styled: 11.11.5 @mui/base: 5.0.0-beta.40 @mui/core-downloads-tracker: 5.15.19 @mui/icons-material: ^5.3.1 => 5.15.19 @mui/material: ^5.15.19 => 5.15.19 @mui/private-theming: 5.15.14 @mui/styled-engine: 5.15.14 @mui/system: 5.15.15 @mui/types: 7.2.14 @mui/utils: 5.15.14 @types/react: ^18.2.18 => 18.3.3 react: 18.3.1 react-dom: 18.3.1 typescript: 4.8 => 4.8.4 ```npx @mui/envinfo
Testing on Chrome v125.0.6422.77
Search keywords: useContext, Invalid hook call, npm link, yarn linkn