Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Getting Material UI from CDN #309

Answered by rmorshea
jamieRowen asked this question in Question
Discussion options

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.

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
2 replies
Comment options

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.

Comment options

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

Answer selected by rmorshea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /