-
-
Notifications
You must be signed in to change notification settings - Fork 383
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: Can't resolve '@mui/icons-material' #88
Comments
Follow the full install instructions and you should be good https://www.material-react-table.com/docs/getting-started/install#install-with-required-peer-dependencies-(recommended) If you are replacing all icons with your custom ones, I think they should get code splitted out |
Actually after some testing, it looks like they don't get code splitted out. This could probably be improved. |
@KevinVandy Can you maybe fix this error? |
Even if you use other icons, you still have to install all of the peer dependencies |
Yeah but the icons could be defined as optional peer dep |
How would the imports work internally? I didn't know this was possible. |
https://stackoverflow.com/questions/62047806/how-do-i-set-a-peer-dependency-optional Maybe you can import icons dynamcially with import() only if its not set by the icons property? |
@BennyAlex I've known that can be done in a normal app using webpack, but didn't know about rollup. Guess I'll try. Feel free to make a PR yourself too though if you want credit or know exactly what needs to be done |
@BennyAlex I tried for 30 minutes and came up with this for export interface MRT_Icons {
ArrowDownwardIcon: any;
ArrowRightIcon: any;
CancelIcon: any;
ClearAllIcon: any;
CloseIcon: any;
DensityLargeIcon: any;
DensityMediumIcon: any;
DensitySmallIcon: any;
KeyboardDoubleArrowDownIcon: any;
DragHandleIcon: any;
DynamicFeedIcon: any;
EditIcon: any;
ExpandMoreIcon: any;
FilterAltIcon: any;
FilterListIcon: any;
FilterListOffIcon: any;
FullscreenExitIcon: any;
FullscreenIcon: any;
MoreHorizIcon: any;
MoreVertIcon: any;
PushPinIcon: any;
RestartAltIcon: any;
SaveIcon: any;
SearchIcon: any;
SearchOffIcon: any;
SortIcon: any;
ViewColumnIcon: any;
VisibilityOffIcon: any;
}
export async function loadIcons() {
try {
const [
ArrowDownwardIcon,
ArrowRightIcon,
CancelIcon,
ClearAllIcon,
CloseIcon,
DensityLargeIcon,
DensityMediumIcon,
DensitySmallIcon,
DragHandleIcon,
DynamicFeedIcon,
EditIcon,
ExpandMoreIcon,
FilterAltIcon,
FilterListIcon,
FilterListOffIcon,
FullscreenExitIcon,
FullscreenIcon,
KeyboardDoubleArrowDownIcon,
MoreHorizIcon,
MoreVertIcon,
PushPinIcon,
RestartAltIcon,
SaveIcon,
SearchIcon,
SearchOffIcon,
SortIcon,
ViewColumnIcon,
VisibilityOffIcon,
] = await Promise.all([
import('@mui/icons-material/ArrowDownward')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/ArrowRight')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/Cancel')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/ClearAll')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/Close')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/DensityLarge')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/DensityMedium')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/DensitySmall')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/DragHandle')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/DynamicFeed')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/Edit')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/ExpandMore')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/FilterAlt')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/FilterList')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/FilterListOff')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/FullscreenExit')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/Fullscreen')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/KeyboardDoubleArrowDown')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/MoreHoriz')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/MoreVert')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/PushPin')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/RestartAlt')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/Save')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/Search')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/SearchOff')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/Sort')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/ViewColumn')
.then((module) => module.default)
.catch(() => null),
import('@mui/icons-material/VisibilityOff')
.then((module) => module.default)
.catch(() => null),
]);
return {
ArrowDownwardIcon,
ArrowRightIcon,
CancelIcon,
ClearAllIcon,
CloseIcon,
DensityLargeIcon,
DensityMediumIcon,
DensitySmallIcon,
DragHandleIcon,
DynamicFeedIcon,
EditIcon,
ExpandMoreIcon,
FilterAltIcon,
FilterListIcon,
FilterListOffIcon,
FullscreenExitIcon,
FullscreenIcon,
KeyboardDoubleArrowDownIcon,
MoreHorizIcon,
MoreVertIcon,
PushPinIcon,
RestartAltIcon,
SaveIcon,
SearchIcon,
SearchOffIcon,
SortIcon,
ViewColumnIcon,
VisibilityOffIcon,
};
} catch (error) {
return undefined;
}
} |
Actually, combining it with this makes it actually work, but with the caveat that the table now renders with a stutter at first as the icons get imported at runtime instead of compile time const [defaultIcons, setDefaultIcons] = useState<MRT_Icons>();
useEffect(() => {
const _loadIcons = async () => {
const icons = await loadIcons();
setDefaultIcons(icons);
};
_loadIcons();
}, []);
const _icons = useMemo(() => ({ ...defaultIcons, ...icons }), [defaultIcons, icons]); This has been fun, and maybe I'll publish an experimental alpha for you to try @BennyAlex . I'm not sure if I should ship it though |
Nice work. |
material-react-table version
1.0.7
Describe the bug and the steps to reproduce it
Just installed it and copied the example provided in the home page and got that error, not sure if it can be removed completely or be added to the dependency list
Your Minimal, Reproducible Example - Sandbox (Recommended) or code snippets
No code required, I was able to fix this by installed
@mui/icons-material
separately, I'm usingreact-icons
as a main icons lib instead but was forced to download the icons material in order to make the table workScreenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
Yes, I think I know how to fix it and will discuss it in the comments of this issue
Terms
The text was updated successfully, but these errors were encountered: