Open smallet-microbiome opened 1 year ago
It doesn't look like this bug report has enough info for one of us to reproduce it.
Please provide a CodeSandbox (https://material-ui.com/r/issue-template-latest), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem.
Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve
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.
@mnajdova - it's not possible to provide a minimal example with CodeSandbox. This error only appears when bundling with webpack, as the original poster mentioned.
I confirm the normalizeIcon
work around makes the job, but it would be great not to have to use it.
For people that only have this problem in their jest tests, you can use the moduleNameMapper trick from here to simply ignore the icon modules:
{
"jest":{
"moduleNameMapper": {
"@mui/icons-material/.*": "<rootDir>/__mocks__/fileMock.js",
},
}
}
Beware: this may produce problems for screenshot and snapshot testing.
Possibly related to https://github.com/mui/material-ui/issues/35233 ?
Duplicates
Latest version
Steps to reproduce πΉ
Link to live example:
Steps:
Set @mui and @emotion as a peer dependency (see config file below)
rollup (see config below) and publish the lib
Create a simple react application, with a component SuperDummy using Dummy from the lib
Write a unit test using SuperDummy => the test should fail with an error like React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
Current behavior π―
On one side I have a component library using react, mui and emotion as peerDep.
package.json
rollup config (note the regexp for @emotion and @mui)
Lib is published with npm.
On the other side, I have a simple react application (storybook, webpack5) Nothing special on the config on this side.
When I run storybook, it works fine. When I run the app, it works fine too.
But when I run the jest unit tests, I get this error:
I managed to surface that the error occurs as soon as I have a default import in the component library. Like
import Paper from '@mui/material/Paper
instead ofimport { Paper } from '@mui/material';
For those basic imports, I can leave with the second import, but then, I need to use icons too (or styled from @emotion/styled)
And these imports are only default:
import Circle from '@mui/icons-material/Circle';
As a workaround, I made this wrap and now it works but it's not ideal:
Expected behavior π€
I would like to be able to use default imports without any error.
For instance:
import Circle from '@mui/icons-material/Circle';
Context π¦
I will have several applications and I want to share theme and components. Hence the creation of the component library. I want to be able to use the component library from the apps whatever the way the component library makes it's imports.
Your environment π
I used FireFox. ``` System: OS: Linux 6.0 Fedora Linux 36 (Workstation Edition) Binaries: Node: 18.1.0 - /usr/bin/node Yarn: Not Found npm: 8.8.0 - /usr/bin/npm Browsers: Chrome: Not Found Firefox: 107.0.1 npmPackages: @emotion/react: ^11.10.5 => 11.10.5 @emotion/styled: ^11.10.5 => 11.10.5 @mui/base: 5.0.0-alpha.110 @mui/core-downloads-tracker: 5.11.0 @mui/icons-material: ^5.10.15 => 5.11.0 @mui/material: ^5.10.15 => 5.11.0 @mui/private-theming: 5.11.0 @mui/styled-engine: 5.11.0 @mui/system: 5.11.0 @mui/types: 7.2.3 @mui/utils: 5.11.0 @types/react: ^18.0.3 => 18.0.26 react: ^18.2.0 => 18.2.0 react-dom: ^18.2.0 => 18.2.0 typescript: ^4.6.3 => 4.9.4 ```npx @mui/envinfo