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

Stage 3 decorators throwing syntax error #221

Closed
b3nten opened this issue Jun 27, 2024 · 1 comment
Closed

Stage 3 decorators throwing syntax error #221

b3nten opened this issue Jun 27, 2024 · 1 comment

Comments

@b3nten
Copy link

b3nten commented Jun 27, 2024

While Vite 5.3 updated esbuild to support stage 3 decorators, and SWC has supported it for a while, when I enable the react plugin it throws the following error (using mobx):

[plugin:vite:react-swc] × Unexpected token `@`. Expected identifier, string literal, numeric literal or [ for the computed key @observable

When I disable the plugin it works fine, but of course I don't have react refresh anymore. Here is my vite config:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  plugins: [
    tailwindcss(),
    react({
      devTarget: "es2022",
    })
  ],
  css: {
    transformer: "lightningcss"
  },
  esbuild: {
    target: "es2022"
  }
})```
@ArnaudBarre
Copy link
Member

I've look into it and the support from SWC is not quite there (it can be added by using https://swc.rs/docs/configuration/compilation#jsctransformdecoratorversion), but it not as stable in SWC as in esbuild. I've updated the description of #86 to reflect this and I'm closing this as duplicate.

For now you can either patch to opt-in to unstable 2022-03 or use the legacy one (both as declared supported by mobx) using tsDecorators option (requires using TS/TSX source code)

@ArnaudBarre ArnaudBarre closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2024
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

Successfully merging a pull request may close this issue.

2 participants