Svelte + EsBuild + Deno - Uncaught TypeError: Cannot read properties of undefined (reading '$$')

I am using Deno and I am getting this error in the browser: Uncaught TypeError: Cannot read properties of undefined (reading '$$')

This is 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: [
    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: [
    logLevel: "info"


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

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


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

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

https://github.com/sveltejs/svelte/issues/6584 States it has to do with my svelte version but I am running npm:esbuild-svelte, which versions don't line up with the svelte versions so I'm not sure how to fix this. What am I doing wrong?


  • Well after a few days of working on something else, it dawned on me that the tag was in the header and at that point, the document.body wouldn't exist. I added an enclosing 'DOMContentLoaded' listener and now it works.