vite icon indicating copy to clipboard operation
vite copied to clipboard

Support javascript decorators

Open mantou132 opened this issue 9 months ago • 4 comments

Description

Support javascript decorators

Suggested solution

Update esbuild to v0.21

Alternative

No response

Additional context

No response

Validations

mantou132 avatar May 07 '24 03:05 mantou132

~how support javascript decorators for production build~

esbuild target: es2022

mantou132 avatar May 13 '24 01:05 mantou132

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

jindong-zhannng avatar May 14 '24 14:05 jindong-zhannng

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

CollinHerber avatar May 15 '24 15:05 CollinHerber

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

bluwy avatar May 18 '24 10:05 bluwy

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' }],
        ],
      },
    }),
  ],
})

firelizzard18 avatar May 31 '24 23:05 firelizzard18

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

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

aleclarson avatar Jun 14 '24 20:06 aleclarson