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 has stopped working in one of my projects #8899

Open
djalbat opened this issue Apr 27, 2024 · 2 comments
Open

SWC has stopped working in one of my projects #8899

djalbat opened this issue Apr 27, 2024 · 2 comments
Assignees
Labels
Milestone

Comments

@djalbat
Copy link

djalbat commented Apr 27, 2024

Describe the bug

I use SWC in dozens of projects but bizarrely it has stopped working in just one. It fails to transpile JSX despite the correct JSX flag being present in the .swcrc file, again like dozens of other projects.

I think the easiest thing to do is to just clone the project and have a look. So:

git clone git@github.com:djalbat/reaction-with-style.git

Then the usual:

npm run install

And then just build:

npm run build-debug

I get errors like:

swc failed:

  x Expression expected
    ,-[lib/example.js:16:1]
 16 | 
 17 | ReactDOM.render(
 18 | 
 19 |     <View/>
    :     ^
 20 | 
 21 |   ,
 22 |   bodyDOMElement
    `----

Clearly a problem with JSX.

Input code

ReactDOM.render(

    <View/>

  ,
  bodyDOMElement
);

Config

{
    "jsc": {
        "parser": {
            "syntax": "ecmascript",
            "jsx": true
        }
    },
    "module": {
        "type": "commonjs"
    }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.100&code=H4sIAAAAAAAAAwtKTUwucfH31StKzUtJLdLg4lIAApuwzNRyfTsQRweIk%2FJTKoFqXHNSc1PzSrg0rbkAjfPNzzcAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D

SWC Info output

No response

Expected behavior

It should transpile just fine!

Actual behavior

See above.

Version

"@swc/core": "^1.2.50"

Additional context

Note that in the playground link, if you toggle the JSX flag then you get the behaviour that I have outlined.

So the problem seems to be that SWC is ignoring the configuration file for some reason.

@djalbat djalbat added the C-bug label Apr 27, 2024
@kdy1 kdy1 added this to the Planned milestone Apr 27, 2024
@kdy1 kdy1 self-assigned this Apr 27, 2024
@kdy1
Copy link
Member

kdy1 commented Apr 29, 2024

Please provide a minimal reproduction.
I can't repro with your repository, and if you know the first version that breaks, it would also help

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
@djalbat
Copy link
Author

djalbat commented Apr 29, 2024

My sincere apologies, this is my oversight.

I fixed the problem after opening this issue by pinning the @swc/core version to one I knew that worked, specifically 1.2.50. I then committed this change so this is the one you would have tried.

I have just tried to replicate the bug by cloning the repository again and doing the following:

npm install @swc/core@latest

However I now cannot replicate it either.

I also stupidly did not supply you with the exact SWC version when I opened this issue. Not the one in the package.json file but the actual one that got installed when I ran npm install. So now I guess we are stuck.

I did not imagine the bug, however. It seemed to be a case of SWC not reading the configuration file, or at least not reading it properly, because it was not compiling the JSX.

I will leave the issue closed. It is up to you if you want to pursue this any further. In a meantime I have pinned the version in all of my repositories, around fifty in all:

"@swc/core": "1.2.50"

At some later date I will un-pin it again and if the bug resurfaces then I will let you know.

@kdy1 kdy1 reopened this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants