我正在使用Deno,但在浏览器中收到以下错误:Uncaught TypeError: Cannot read properties of undefined (reading '$$')

这是bunder.ts:

import * as esbuild from 'https://deno.land/x/esbuild@v0.11.12/mod.js'
import sveltePlugin from 'npm:esbuild-svelte';
import { typescript } from "./build/esbuild-svelte.ts"; // I rebuilt svelte-process-esbuild in ts because it wasn't originally written in ts
// if you want this code to duplicate, I can get it to you np

const result = await esbuild.build({
    entryPoints: [
        'client/entries/admin.ts',
        'client/entries/main.ts'
    ],
    bundle: true,
    outdir: 'dist',
    mainFields: ["svelte", "browser", "module", "main"],
    conditions: ["svelte", "browser"],
    watch: {
        onRebuild(error: Error, result: any) {
            if (error) console.error('watch build failed:', error);
            else console.log('watch build succeeded:', result);
        }
    },
    // Deno did not recognise sveltePlugin as a function, but running the code works
    plugins: [(sveltePlugin as unknown as Function)({
        preprocess: [
            typescript()
        ]
    })],
    logLevel: "info"
});

Svelte App.Svelte:

<script lang="ts">
    export let name: String;
</script>

<main>Hello, {name}</main>

./CLIENT/ENTRIES/main.ts:

import App from '../views/App.svelte';

const app = new App({
    target: document.body,
    props: {
        name: 'World'
    }
});

https://github.com/sveltejs/svelte/issues/6584个 说明这与我的svelte版本有关,但我运行的是npm:esbuild-svelte,这些版本与svelte版本不一致,所以我不确定如何修复这个问题.我做错了什么?

推荐答案

在做了几天的其他工作后,我突然意识到标签在标题中,在这一点上,document.body不会存在.我添加了一个封闭的'DOMContentLoaded'监听器,现在它可以工作了.

Typescript相关问答推荐

Angular 17 Select 错误core.mjs:6531错误错误:NG 05105:发现意外合成监听器@transformPanel.done

需要使用相同组件重新加载路由变更数据—React TSX

如何使用泛型类型访问对象

Angular 行为:属性类型从SignalFunction更改为布尔

如何按不能保证的功能过滤按键?

如何重构长联合类型?

类型脚本返回的类型包含无意义的泛型类型名称

如何在Reaction Query Builder中添加其他字段?

如何 bootstrap TS编译器为类型化属性`T`推断正确的类型?

保护函数调用,以便深度嵌套的对象具有必须与同级属性函数cargument的类型匹配的键

为什么我的动画状态在组件实例之间共享?

不带其他属性的精确函数返回类型

为什么&Quot;元素隐式具有';Any';类型,因为...即使我已经打字了,也不能作为索引显示错误吗?

使用或属性编写无限嵌套的接口

字幕子集一个元组的多个元素

为什么类型脚本使用接口来声明函数?他的目的是什么.

从泛型对象数组构造映射类型

显式推断对象为只读

React router - 如何处理嵌套路由?

从函数参数推断函数返回类型