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

Using the export keyword between a decorator and a class is not allowed. Please use export @dec class instead. #9641

Closed
geersch opened this issue Oct 14, 2024 · 5 comments · Fixed by #9644
Assignees
Labels

Comments

@geersch
Copy link

geersch commented Oct 14, 2024

Describe the bug

We are using Vitest to run tests for a NestJS application which relies on legacy decorators. SWC is used to do the transpilation. After updating from version 1.7.28 to 1.7.35 tests started failing.

Input code

NestJS provider.

@Injectable()
export class MyService { }

Test suite.

import { MyService } from './MyService.js';

describe('MyService', () => {
  it('should test something', async () => {
    const service = new MyService();
    ...
  });
});

Config

Using the unplugin-swc plugin for Vitest to configure SWC.

import swc from 'unplugin-swc';

const vitestConfig = {
  test: { ... },
  plugins: [
    ...,
    swc.vite({
       module: { type: 'es6' },
    }),
  ]
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.35&code=H4sIAAAAAAAAA0srzUsuyczPU%2FDMy0pNLklMyknVSM7PKy4pKk0uyS%2ByUnCDKtBUqObiquXickBSqMmVnJNYXKzgWxmcWlSWmZwKVgMAKWCzZFMAAAA%3D&config=H4sIAAAAAAAAA22RzU7DQAyE7zxFtOKImoIEh94QVSUO8A5m47Rb9k%2B2IxpVeXecn0ah9GjPtzMe7fmuKMw92wMGMJvCHEQyb8qSf%2ByKuByF1ZFTNA89GlLVeFTyrJPO0uZ%2BMsgvRjfdAB3ZLgigPcrIPK0fnwcf3WcgRpo53XAbBU492buyJZdlolWt0CYCScRKCDU4Ky7kRPLKaicuxYs%2ByN2UJgSR60RhGehxD7bdXoyvfefEDxSoQOAaaBi3WLuIu0RvHph3Dn11M%2F8bMQ%2FIJwT828DgKSO5gNreL8%2Fr37yP3UTIfTWC%2F7pjcFNzveEGXIPn6ZL5e4KLrm5nsfsF2uTyGAQCAAA%3D

SWC Info output

Operating System:
    Platform: darwin
    Arch: arm64
    Machine Type: arm64
    Version: Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000
    CPU: (10 cores)
        Models: Apple M1 Pro

Binaries:
    Node: 20.17.0
    npm: 10.8.2
    Yarn: 4.4.0
    pnpm: 8.15.5

Relevant Packages:
    @swc/core: 1.7.35
    @swc/helpers: N/A
    @swc/types: 0.1.13
    typescript: 5.6.2

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

The compiled output should not break. Same as version 1.7.26.

Actual behavior

Either we get the error Using the export keyword between a decorator and a class is not allowed. Please use export @dec class instead. or SyntaxError: Invalid or unexpected token.

Version

1.7.35

Additional context

No response

@kdy1
Copy link
Member

kdy1 commented Oct 15, 2024

Can you try changing the target to something other than esnext? I think this is #9640 but I can't be sure as there's no repro.

@kdy1 kdy1 self-assigned this Oct 15, 2024
@geersch
Copy link
Author

geersch commented Oct 15, 2024

Yes, looks to be related. In another project which doesn't target ESM version 1.7.35 does not cause these issues.

@boan-anbo
Copy link

Same error, same set up (NestJS + swc + Vitest). Targeting ES2022 instead of ESNext works OK for now, but not ES2023.

@kdy1 kdy1 closed this as completed in 8a19201 Oct 15, 2024
@geersch
Copy link
Author

geersch commented Oct 16, 2024

Version 1.7.36 resolves the issue for me. Thanks!

@swc-bot
Copy link
Collaborator

swc-bot commented Nov 15, 2024

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 Nov 15, 2024
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.

4 participants