Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svelte-kit preview throws "Cannot destructure property 'cancelable' of 'undefined' as it is undefined" during dispatch custom event call. #4988

Closed
bhvngt opened this issue May 19, 2022 · 5 comments

Comments

@bhvngt
Copy link

bhvngt commented May 19, 2022

Describe the bug

while dispatching a custom event, following error gets thrown.

index-e29e855b.js:304 Uncaught TypeError: Cannot destructure property 'cancelable' of 'undefined' as it is undefined.
    at index-e29e855b.js:304:27
    at HTMLButtonElement.decrease (index.svelte-50532f6b.js:84:5)

This happens only when I run svelte-kit build && svelte-kit preview. Its little baffling because svelte source code correctly defines default parameter to the third parameter. However, on build, the default value gets stripped out. I tried with non-minified build also and see the same result.

Workaround: Currently a simple workaround is to pass an empty third parameter to dispatch method.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-9twecw?file=src/lib/Counter.svelte

On the console, cancel the svelte-kit dev process and then start npm run build && npm run preview command.

When - or + button is clicked, a custom dispatch event is called. ideally it should print the show the current count in the parent component. However, on my browser, above error is thrown.

Logs

index-e29e855b.js:304 Uncaught TypeError: Cannot destructure property 'cancelable' of 'undefined' as it is undefined.
    at index-e29e855b.js:304:27
    at HTMLButtonElement.decrease (index.svelte-50532f6b.js:84:5)

System Info

System:
    OS: macOS 12.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 75.91 MB / 32.00 GB
    Shell: 3.4.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 18.1.0 - ~/Library/Caches/fnm_multishells/69089_1652879820227/bin/node
    Yarn: 1.22.15 - ~/Library/Caches/fnm_multishells/69089_1652879820227/bin/yarn
    npm: 8.8.0 - ~/Library/Caches/fnm_multishells/69089_1652879820227/bin/npm
  Browsers:
    Chrome: 101.0.4951.64
    Chrome Canary: 104.0.5069.0
    Firefox: 99.0
    Firefox Developer Edition: 101.0
    Safari: 15.4
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.43
    @sveltejs/kit: next => 1.0.0-next.335
    svelte: ^3.48.0 => 3.48.0

Severity

annoyance

Additional Information

I thought of raising it in this repo, since the issue is happening during the svelte-kit build.

@lemmon
Copy link

lemmon commented May 19, 2022

Thank you! I've just spent several hours debugging my code.

I fould that the issue starts with SVELTE version 3.48.0. Everything works just fine with version up to 3.47.0.

I have my suspicion that it might have something to do with this feature:

Allow creating cancelable custom events with createEventDispatcher (sveltejs/svelte#4623)

@Conduitry
Copy link
Member

Weird. I wonder whether we're running into a Rollup/Terser/esbuild optimization bug? The unoptimized code in createEventDispatcher does look like it would avoid this, as you noted.

@bluwy
Copy link
Member

bluwy commented May 19, 2022

It looks like a regression in Rollup 2.74.0, specifically rollup/rollup#4498. I've created an issue there to track it: rollup/rollup#4507

@bluwy bluwy closed this as completed May 19, 2022
@bluwy
Copy link
Member

bluwy commented May 19, 2022

Update: Rollup 2.74.1 is released with a revert for the feature, until it's ironed out.

@yekta
Copy link

yekta commented May 21, 2022

Having the same problem. Spent a couple of hours trying to understand what's going on but couldn't until I saw this issue. It's actually making some libraries not work in my case.

Edit: Tried with SvelteKit version 1.0.0-next.338 and error is gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants