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

Support javascript decorators #16616

Closed
4 tasks done
mantou132 opened this issue May 7, 2024 · 6 comments · Fixed by #17290
Closed
4 tasks done

Support javascript decorators #16616

mantou132 opened this issue May 7, 2024 · 6 comments · Fixed by #17290
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request
Milestone

Comments

@mantou132
Copy link

mantou132 commented May 7, 2024

Description

Support javascript decorators

Suggested solution

Update esbuild to v0.21

Alternative

No response

Additional context

No response

Validations

@sapphi-red sapphi-red added this to the 5.3 milestone May 7, 2024
@sapphi-red sapphi-red added enhancement New feature or request dependencies Pull requests that update a dependency file and removed enhancement: pending triage labels May 7, 2024
@mantou132
Copy link
Author

mantou132 commented May 13, 2024

how support javascript decorators for production build

esbuild target: es2022

@jindong-zhannng
Copy link

Is there a work around at current stage except for waiting for the next version of vite?

@CollinHerber
Copy link

The frontend framework I use is now using Javascript decorators and I cannot update to the latest version because of this.
Hoping to see the update in ESBuild to support this soon! <3

@bluwy
Copy link
Member

bluwy commented May 18, 2024

If you want to upgrade esbuild now for your project, you can use overrides. This would be updated in the next minor.

@firelizzard18
Copy link

firelizzard18 commented May 31, 2024

FYI this does not work with an ESNext or ES2022 target. Setting the target to ES2020 does work, but a newer target fails:

error during build:
RollupError: Unexpected token `@`. Expected identifier, string literal, numeric literal or [ for the computed key
    at getRollupError (file:///path/to/project/node_modules/rollup/dist/es/shared/parseAst.js:396:41)
    at ParseError.initialise (file:///path/to/project/node_modules/rollup/dist/es/shared/node-entry.js:11332:28)
    at convertNode (file:///path/to/project/node_modules/rollup/dist/es/shared/node-entry.js:13082:10)
    at convertProgram (file:///path/to/project/node_modules/rollup/dist/es/shared/node-entry.js:12399:12)
    at Module.setSource (file:///path/to/project/node_modules/rollup/dist/es/shared/node-entry.js:14246:24)
    at async ModuleLoader.addModuleSource (file:///path/to/project/node_modules/rollup/dist/es/shared/node-entry.js:18892:13)

It's also worth noting that you need to update the babel config if you want vite to work:

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

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react({
      babel: {
        plugins: [
          ['@babel/plugin-proposal-decorators', { version: '2023-11' }],
        ],
      },
    }),
  ],
})

@aleclarson
Copy link
Member

Note that #17290 is not enough to get "JS decorator" support.

You also need to set esbuild: { target: 'es2022' } in your Vite config.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants