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

SWC Compress + Svelte = Error #8183

Closed
rikschennink opened this issue Jan 10, 2023 · 1 comment
Closed

SWC Compress + Svelte = Error #8183

rikschennink opened this issue Jan 10, 2023 · 1 comment

Comments

@rikschennink
Copy link

rikschennink commented Jan 10, 2023

Describe the bug

I don't know wether this problem originates in Svelte or in SWC, I lean towards SWC but will still post it here just to be sure.

When I enable compress in the .swcrc config and then compress a Svelte built target the resulting file will throw an error when loaded in a browser.

I've set up a repository here: https://github.com/rikschennink/swc-svelte-problem

I ran into this because NextJS has enabled SWC to compress JS and since that time my Svelte based library can no longer be used with NextJS unless NextJS is configured to use Terser as JS compressor.

Reproduction

https://github.com/rikschennink/swc-svelte-problem

Logs

Uncaught TypeError: Cannot read properties of undefined (reading 'context')
    at I (test-swc.js:197:49)
    at new ft (test-swc.js:336:43)
    at swc.html:18:13

This error is thrown because current_component.$$ (Svelte specific) is somehow missing.

We can circumvent this by passing context: [] to the App constructor but now the error will be thrown on the App child component.

System Info

System:
    OS: macOS 13.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 42.95 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.10.0 - ~/.nvm/versions/node/v16.10.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.10.0/bin/yarn
    npm: 7.15.1 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 102.1.39.122
    Chrome: 108.0.5359.124
    Chrome Canary: 111.0.5530.0
    Firefox: 108.0.1
    Firefox Nightly: 104.0a1
    Safari: 16.2
  npmPackages:
    svelte: ^3.52.0 => 3.55.0

Severity

This is not stopping me from upgrading, not stopping me from using svelte, but it's a lot more than an annoyance 😅

@rikschennink
Copy link
Author

Will close because this seems to be a bug in SWC

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2023
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

2 participants