感谢Rutuja的答案,我也成功让我的应用程序运行起来了。除了Rutuja的答案之外,如果有人在使用Sapper + Svelte +其他包(在我的情况下是theme.js
)时遇到此问题,您可能还需要导入多个组件。这在Mozilla的文档中关于导入的部分中有描述。
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');
}
})();
针对我自己的项目(使用theme.js
),我不得不使用以下逻辑(基于位于这里的svelte示例中的theme.js
):
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)
})
onMount(() => { return () => { // on destroy code }})
。 - user5819540