owlsdepartment / vite-plugin-babel

Runs babel during dev serve in Vite
MIT License
51 stars 14 forks source link

RollupError: Unexpected token `@`. during build while using it with @babel/plugin-proposal-decorators #24

Open Verthon opened 4 months ago

Verthon commented 4 months ago

Hello

I run into following issue: RollupError: Unexpected token@. Expected identifier, string literal, numeric literal or [ for the computed key when running build with the Vite

Dependencies:

Decorator usage:

function log<
    Type,
    Context extends ClassMethodDecoratorContext | ClassFieldDecoratorContext,
    ReturnType
>(message: Type): (_: unknown, context: Context) => ReturnType {
    //@ts-ignore
    return (_, context) => {
        if (context.kind === "method") {
            return () => message;
        }

        return () => () => message;
    };
}

export class Example {
    @log("test")
    public doSomething = () => {
        console.log("test");
    };
}

Reproduction repository: https://github.com/Verthon/babel-plugin-decorators-repro

Current workaround:

we are using @vitejs/plugin-react even we don't use React 😅 but it works

react({
      babel: {
        plugins: [
          ['@babel/plugin-proposal-decorators', { version: '2023-05' }],
        ],
      },
}),