I'm using Rails 5.1.4 with the code below. I have confirmed that the material.js file is being processed and the material-components-web module is downloaded and discovered.
Why is mdc undefined when calling window.mdc.autoInit()?
// app/javascript/packs/material.js
import 'material-components-web'
// app/views/layouts/application.html.eeb
<html>
<head>
<%= javascript_pack_tag 'material' %>
</head>
<body>
<script>window.mdc.autoInit();</script>
</body>
</html>
I have tried
- importing
@material/auto-initseparately. - Putting the
autoInitcall inside an onload - Adding a
console.dir(window)/console.dir(this)inside pack file.thisis notwindowinside the the pack file and the exports aren't being attached tothis
To make
material-components-webwork with Rails I didAnd then I made sure
window.mdc.autoInit()was called at the end of the body