-
-
Notifications
You must be signed in to change notification settings - Fork 328
Getting Material UI from CDN #309
-
HI,
I was wondering whether it is possible to grab the JS components from CDN rather than a local install. Going with the docs and the material UI example I thought I might be able to use idom.Module on a URL, so was hoping to replace idom.install('@material-ui/core') with idom.Module('https://unpkg.com/@material-ui/core@4.11.3/umd/material-ui.production.min.js')
Whilst this does not cause any errors on the python side of things, I do get a JS error in the browser
TypeError: Cannot use 'in' operator to search for 'default' in undefined
at material-ui.production.min.js:6
Am i missing something obvious here? Apologies in advance for any naivety.
Beta Was this translation helpful? Give feedback.
All reactions
I'm not a JS wizard though, so I could be wrong about this, but I'm pretty sure this is because Material UI is using bare imports. If you check out some of the code from the CDN you'll find the following snippet:
require("react")
The problem here is that RequireJS is going to look for React at ./react when IDOM is actually hosting it at ./react.js.
Thankfully there looks to be a solution to this problem of bare imports on the horizon in the form of Import Maps.
Until then though, you'll need need to install it locally. Be sure to post here again if you have installation problems.
Replies: 1 comment 2 replies
-
I'm not a JS wizard though, so I could be wrong about this, but I'm pretty sure this is because Material UI is using bare imports. If you check out some of the code from the CDN you'll find the following snippet:
require("react")
The problem here is that RequireJS is going to look for React at ./react when IDOM is actually hosting it at ./react.js.
Thankfully there looks to be a solution to this problem of bare imports on the horizon in the form of Import Maps.
Until then though, you'll need need to install it locally. Be sure to post here again if you have installation problems.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks very much for this very prompt reply, locally I had no issues at all, I was just testing things out on a deployment server that didn't have npm installed.
I think this project looks really interesting though and will definitely be keeping an eye on it over the coming months.
Beta Was this translation helpful? Give feedback.
All reactions
-
There is a way to install JS without NPM, but it just requires you to wrap a JS bundle up in a Python package. There's a template for doing that though: https://github.com/idom-team/idom-react-component-cookiecutter
Beta Was this translation helpful? Give feedback.