Trying to create some reusable components for our Electron screen using lit-html
. When I attempt to add an example component I run into an error.
Using electron: ^5.0.6
Trying to import module my-element.js
(most of this code is example code and I'm just trying to get it working)
<head>
<!-- Polyfills only needed for Firefox and Edge. -->
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@latest/webcomponents-loader.js"></script>
</head>
<body>
<!-- Works only on browsers that support Javascript modules like
Chrome, Safari, Firefox 60, Edge 17 -->
<script type="module" src="my-element.js"></script>
The module my-element.js
contains the following:
import {LitElement, html, css} from 'lit-html';
class MyElement extends LitElement {
static get properties() {
return {
mood: {type: String}
}
}
static get styles() {
return css`.mood { color: green; }`;
}
render() {
return html`Web Components are <span class="mood">${this.mood}</span>!`;
}
}
customElements.define('my-element', MyElement);
When the page loads I get an error
Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
I have tried different ways of importing lit-html
but nothing has solved the error.
Ex. import {LitElement, html, css} from '../../node_modules/lit-html/lit-html';
Ex. import {LitElement, html, css} from '../../node_modules/lit-html/lit-html.js';