Thank you to Rutuja's answer here, I was also able to get my application working. Adding to Rutuja's answer, if anyone runs into this issue while using Sapper + Svelte + another package (in my case theme.js
), you may also need to import multiple components. This is described in Mozilla's documentation here for import.
When importing a default export with dynamic imports, it works a bit
differently. You need to destructure and rename the "default" key from
the returned object.
(async () => {
if (somethingIsTrue) {
const { default: myDefault, foo, bar } = await import('/modules/my-module.js');
}
})();
For my own project (using theme.js
), I had to use the following logic (based on the svelte example for theme.js
located here):
const themeState = {
active: undefined,
selected: undefined,
themes: [],
}
onMount(async () => {
const { default: Themer, auto, system } = await import('themer.js')
themeState = {
active: undefined,
selected: light,
themes: [light, dark, auto, system],
}
const themer = new Themer({
debug: true,
onUpdate: (theme) => (themeState.active = theme),
themes: { light, dark, auto, system },
})
function noThemeSupport({ theme }) {
return theme === 'system' && !themer.themeSupportCheck()
}
function setTheme(theme) {
themeState.selected = theme
themer.set(theme)
}
themer.set(themeState.selected)
})