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 #6780

Closed
rikschennink opened this issue Jan 10, 2023 · 6 comments · Fixed by #6751
Closed

SWC Compress + Svelte = Error #6780

rikschennink opened this issue Jan 10, 2023 · 6 comments · Fixed by #6751
Assignees
Labels
Milestone

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.

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.

Input code

No response

Config

{
    "jsc": {
        "minify": {
            "compress": true, // set to false and it no longer errors
            "mangle": false
        }
    }
}

Playground link

No response

Expected behavior

It should work with and without compress enabled

Actual behavior

When compress is enabled the Svelte app no longer loads and throws the following error:

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.

Version

1.3.25

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Jan 10, 2023
@kdy1 kdy1 self-assigned this Jan 10, 2023
@kdy1
Copy link
Member

kdy1 commented Jan 10, 2023

This is bug of swc

@rikschennink
Copy link
Author

@kdy1 But what is it caused by, as-in what's it doing wrong, eliminating too much code?

@kdy1
Copy link
Member

kdy1 commented Jan 10, 2023

I don't know. I didn't investigate it yet

@rikschennink
Copy link
Author

Ah okay, it seemed you knew because of the fast reply. 👍

@rikschennink
Copy link
Author

🙏 Waw that was fast. Fingers crossed NextJS pulls this in asap.

@kdy1 kdy1 modified the milestones: Planned, v1.3.26 Jan 11, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Feb 10, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Feb 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants