sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.21k stars 4.09k forks source link

compiled IIFE output does not work with svelte5 but does with svelte4 #10495

Closed lanfeust21 closed 6 months ago

lanfeust21 commented 6 months ago

Describe the bug

The application does not start in the browser app.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'call')

Reproduction

i join 2 simple projects one in svelte4 and the equivalent in svelte 5 -- App.svelte --

Work ID: {workId}

---app.js---- import App from "./App.svelte";

let div = document.createElement("div"); div.id = "app"; document.body.appendChild(div);

const app = new App({ target: document.getElementById('app'), props: { userId: 1 } }); export default app;


cp src/index.html build/. start a local web server, and you will see that in svelte 4 the App is running, not in svelte5.
svelte5_iife.zip svelte4_iife.zip

Logs

app.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'call')
    at se (app.js:1:5462)
    at app.js:1:5786
    at Ue (app.js:1:5835)
    at Ye (app.js:1:5897)
    at new Ge (app.js:1:6174)
    at app.js:1:6327
    at app.js:1:6408

System Info

System:
    OS: macOS 12.6.1
    CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
    Memory: 53.09 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 21.5.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.4.0 - /usr/local/bin/npm
    bun: 1.0.21 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 121.1.62.162
    Chrome: 121.0.6167.184
    Chrome Canary: 114.0.5725.0
    Edge: 121.0.2277.112
    Safari: 16.1
  npmPackages:
    svelte: ^5.0.0-next.54 => 5.0.0-next.54

Severity

blocking all usage of svelte

brunnerh commented 6 months ago

Components are no longer classes.

+ import { createRoot } from 'svelte';
import App from './App.svelte'

- const app = new App({ target: document.getElementById("app") });
+ const app = createRoot(App, { target: document.getElementById("app") });

export default app;