I use typeorm with next.js and typescript, my tsconfig.json is:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext",
"es5",
"es6"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"jsx": "preserve"
},
include: ...
}
I set experimentalDecorator is true. My typescript is 3.9.7 and my typeorm is 0.2.25. The compile error is:
error - ./db/entity/User.ts:7:1
Syntax error: Support for the experimental syntax 'decorators-legacy' isn't currently enabled:
5 |
6 |
> 7 | @Entity()
| ^
8 | export class User {
9 |
10 | @PrimaryGeneratedColumn()
I already enable emitDecoratorMetadata, Hoe to make decorators-legacy enable for tsconfig.json
A coworker of mine has just faced the same problem: this is an error throwed by Babel which can't handle class decorators. In fact, even if you don't use Babel in your code, Next.JS does in the frontend.
Be sure you don't import ./db/entity/User.ts
or any other TypeORM class in your frontend code.