-
Hi, I'm using the latest framework version btw, I tested a simpler react component and also the "greetings" example in the docs and both are fine. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
If you install modules locally, you must remove the However this does not solve the issue: I've tried both approaches, |
Beta Was this translation helpful? Give feedback.
-
It still doesn’t work, but the recommended way to do this now would be to use import Box from "npm:@mui/material/Box";
import {SimpleTreeView} from "npm:@mui/x-tree-view/SimpleTreeView";
import {TreeItem} from "npm:@mui/x-tree-view/TreeItem";
function FirstComponent() {
return (
<Box sx={{ minHeight: 352, minWidth: 250 }}>
<SimpleTreeView>
<TreeItem itemId="grid" label="Data Grid">
<TreeItem itemId="grid-community" label="@mui/x-data-grid" />
<TreeItem itemId="grid-pro" label="@mui/x-data-grid-pro" />
<TreeItem itemId="grid-premium" label="@mui/x-data-grid-premium" />
</TreeItem>
<TreeItem itemId="pickers" label="Date and Time Pickers">
<TreeItem itemId="pickers-community" label="@mui/x-date-pickers" />
<TreeItem itemId="pickers-pro" label="@mui/x-date-pickers-pro" />
</TreeItem>
<TreeItem itemId="charts" label="Charts">
<TreeItem itemId="charts-community" label="@mui/x-charts" />
</TreeItem>
<TreeItem itemId="tree-view" label="Tree View">
<TreeItem itemId="tree-view-community" label="@mui/x-tree-view" />
</TreeItem>
</SimpleTreeView>
</Box>
);
}
display(<FirstComponent />); But there are a couple challenges here. First is that MUI brings in a fairly enormous tree of 105 dependencies. That dependency graph looks like this: Second is that many of these packages (and many packages in the Node ecosystem in general) are not distributed as standard ES modules; they tend to be distributed as CommonJS packages that are only directly usable in Node.js, requiring transpilation to work in a browser. And hence Framework relies on jsDelivr (esm.run) to convert them into standard ES modules. And one of the problems here is that it isn’t always clear how to convert CommonJS modules into ES modules. The error in the
This is transpiled code which is a bit hard to read, but you can see the import of https://cdn.jsdelivr.net/npm/@mui/[email protected]/Box/index.js/+esm And the imported https://cdn.jsdelivr.net/npm/@mui/[email protected]/createStyled/+esm We expect the default export of the above ES module to be a function. However, jsDelivr seems to have gotten confused, because the default export is a import createStyled from "https://cdn.jsdelivr.net/npm/@mui/[email protected]/createStyled.js/+esm";
display(createStyled); This should display a function, but instead it displays a jsDelivr is likely confused because it’s using a built CommonJS module to create the ES module: https://cdn.jsdelivr.net/npm/@mui/[email protected]/createStyled.js Ironically, MUI does also provide an ES module version of this file, but it isn’t properly declared and so isn’t discoverable by jsDelivr: https://cdn.jsdelivr.net/npm/@mui/[email protected]/esm/createStyled.js esbuild describes the problem of default exports here: https://esbuild.github.io/content-types/#default-interop So, maybe it’s possible to get jsDelivr to workaround these issues in how MUI is packaged, but ideally MUI would adopt standard ES modules in its distribution and declare them using subpath or conditional exports in its package.json. Then downstream consumers wouldn’t try to uncompile the CommonJS modules and could use the ES module source directly. |
Beta Was this translation helpful? Give feedback.
It still doesn’t work, but the recommended way to do this now would be to use
npm:
imports instead of node imports. (When we support a configurable React engine #1465 then you could switch to node imports.) When usingnpm:
imports, you don’t need to install anything, and the example code would look like this: