gpt4 book ai didi

typescript - 对于 typescript ,当前未启用 'decorators-legacy' 的错误,事件我设置了 ExperimentalDecorators 和 emitDecoratorMetadata 为真

转载 作者:行者123 更新时间:2023-12-04 11:36:06 26 4
gpt4 key购买 nike

我将 typeorm 与 next.js 和 typescript 一起使用,我的 tsconfig.json 是:

{
"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: ...

}
我设置experimentalDecorator 为true。我的 typescript 是 3.9.7,我的 typescript 是 0.2.25。
编译错误是:
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()
我已经启用了emitDecoratorMetadata,Hoe 来为tsconfig.json 启用decorators-legacy

最佳答案

我的一个同事刚刚遇到了同样的问题:这是 Babel 抛出的一个错误,它无法处理类装饰器。
事实上,即使你的代码中没有使用 Babel,Next.JS 也会在前端使用。
确保您不导入 ./db/entity/User.ts或前端代码中的任何其他 TypeORM 类。

关于typescript - 对于 typescript ,当前未启用 'decorators-legacy' 的错误,事件我设置了 ExperimentalDecorators 和 emitDecoratorMetadata 为真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63353141/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com