Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The decorators plugin requires a 'decoratorsBeforeExport' option

I'm using Next.js with typescript. I am trying to also use TypeORM, like so:

@Entity()
export class UserModel extends BaseEntity {
  @PrimaryGeneratedColumn('uuid')
  id: number
}

But I'm getting an error:

Error: [BABEL] /home/aironside/Documents/private/tatooify/pages/api/user.ts: The decorators plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you want to use the legacy decorators semantics, you can set the 'legacy: true' option.

Here's my .babelrc

{
  "presets": ["next/babel"],
  "plugins": [
    "@babel/plugin-proposal-decorators", { 
      "legacy": true
     },
  ]
}

And here's the related package.json part

{
  "dependencies": {
    "@babel/plugin-proposal-decorators": "^7.12.13",
    ...
  },
  "devDependencies": {
    ...
  }
}

From what I found, most errors are caused by either not having this plugin installed, or it being in devDep instead of dependencies. What am I missing?

like image 981
Alex Ironside Avatar asked Oct 27 '25 01:10

Alex Ironside


1 Answers

Ok, as shown in the docs (obviously) .babelrc should be like this:

{
  "presets": ["next/babel"],
  "plugins": [
    ["@babel/plugin-proposal-decorators", {"legacy": true}]
  ]
}

Notice the [] around plugin name and options object.

like image 64
Alex Ironside Avatar answered Oct 28 '25 13:10

Alex Ironside



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!