0

I am trying to import a function which returns a lit-html template, and then render it. If I define the function in place, the template successfully renders, however if I try and import the template dynamically, it renders [object Object].

import { render } from "lit-html";
import("/private.js").then(module => {
  // function sayHello(name) {
  //  return html`<h1>Hello ${name}</h1>`;
  // }
  // they appear to be identical objects
  // console.log("mod", module.default("beans")); // this renders properly
  // console.log("new", sayHello("beans")); // this doesn't
  render(module.default("beans"), document.querySelector("#app"));
});

private.js:

import { html } from "lit-html";

export default function sayHello(name) {
  return html`<h1>Hello ${name}</h1>`;
}
Max888
  • 3,089
  • 24
  • 55

1 Answers1

0

The problem is that because the two files are separate builds, both contain lit-html, which causes the error.

Max888
  • 3,089
  • 24
  • 55