-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Module not found @material-ui/core/ThemeProvider when minimizing bundle size in create react app #23208
Comments
FYI. I've tried both import { createMuiTheme } from '@material-ui/core/styles'; and import { createMuiTheme } from '@material-ui/core'; without any luck |
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), 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 |
Nevermind, I think I know what's happening. We changed the bundle layout and this section is now outdated. |
Is there a workaround currently? Or should I wait for this issue to be solved? |
Right now I would not alias |
So you are suggesting not using option 2 for now? |
I suggest using option 1 only for @material-ui/icons only where it has the biggest benefit. Anything not using babel plugins should be safe regardless. |
This issue was first reported in https://twitter.com/_developit/status/1220760229790523392. What if we normalize the file structure to make it work without any configuration? |
The tweet is not about this issue.
We can't since we don't ship the same bundles in each package. |
But the error is not about icons?
which happens on due to the following import import { createMuiTheme } from '@material-ui/core'; Maybe I'm just not understanding exactly what you're telling me here |
Could you provide a small repro with just that code? Sounds very odd that |
While working on a small repo to share I just realized that I had import { CssBaseline, ThemeProvider } from "@material-ui/core"; I now changed that to import { CssBaseline } from "@material-ui/core";
import { ThemeProvider } from "@material-ui/styles"; Now I'm getting this error instead
I'll share a repo in a bit |
Actually I don't think I need to share anything since I've got it working now. Had to do import { createMuiTheme } from "@material-ui/core/styles instead of import { createMuiTheme } from "@material-ui/core and import { ThemeProvider } from "@material-ui/styles"; instead of import { ThemeProvider } from "@material-ui/core"; Below are my relevant files outlined
import { createMuiTheme } from "@material-ui/core/styles";
import { red } from "@material-ui/core/colors";
// A custom theme for this app
const theme = createMuiTheme({
palette: {
primary: {
main: "#556cd6",
},
secondary: {
main: "#19857b",
},
error: {
main: red.A400,
},
background: {
default: "#fff",
},
},
});
export default theme;
import React from "react";
import { CssBaseline } from "@material-ui/core";
import { ThemeProvider } from "@material-ui/styles";
import theme from "./theme";
function App() {
return (
<ThemeProvider theme={theme}>
<CssBaseline />
Hello World
</ThemeProvider>
);
}
export default App;
/* config-overrides.js */
const { useBabelRc, override } = require('customize-cra');
module.exports = override(useBabelRc());
const plugins = [
[
"babel-plugin-transform-imports",
{
"@material-ui/core": {
transform: "@material-ui/core/${member}",
preventFullImport: true,
},
"@material-ui/icons": {
transform: "@material-ui/icons/${member}",
preventFullImport: true,
},
},
],
];
module.exports = { plugins };
{
"name": "muiv5",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/core": "^10.0.35",
"@emotion/styled": "^10.0.27",
"@material-ui/core": "^5.0.0-alpha.14",
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.19.2",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"typescript": "^4.0.5",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired± build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"babel-plugin-transform-imports": "^2.0.0",
"customize-cra": "^1.0.0",
"react-app-rewired": "^2.1.6"
}
}
I'm left with a bit of confusion on the imports though. E.g. I thought I could import |
@eps1lon From what I understand, the tweet mentions that there are a few modules that need an exception because they don't follow the folder convention ( |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
We are reducing the ambition of the scope of the changes in v5. We won't change the folder locations, but instead move one step backward: |
Current Behavior 😯
I get
Expected Behavior 🤔
I don't expect any errors.
Steps to Reproduce 🕹
Since this is a bug related to the project setup then I can't make a codesandbox for it
Steps:
5.0.0-alpha.13
npm add -D babel-plugin-transform-imports react-app-rewired customize-cra
package.json
and create.babelrc.js
,config-overrides.js
files as outlined in the docs.Context 🔦
Your Environment 🌎
The text was updated successfully, but these errors were encountered: