So I’m new to Nuxt ecossystem, I’m coming from years of Laravel/PHP use, even tho I’m familiar with Vue/TypeScript.
I just can’t make it work properly, the problem I’m facing is that I can’t set the proper TypeScript config for Nitro
TypeORM requires me to set both of those flags as true to work:
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
The problem is, I’ve already set it on my main tsconfig.json
and also in server/tsconfig.json
, it just don’t work.
{
"extends": "../.nuxt/tsconfig.server.json",
"compilerOptions": {
"target": "ESNext",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}
I got this error despite my correct tsconfig.json
settings:
ERROR: Transforming JavaScript decorators to the configured target environment (“es2019”) is not supported yet
Transforming JavaScript decorators to the configured target environment (“es2019”) is not supported yet
It can’t figure out how to handle the TypeORM decorator:
@Entity() // This one
export class User {
@PrimaryColumn()
id: number
}
Digging on the internet I found a workaround for that which is set the TypeScript config in the nuxt.config.ts
like that:
nitro: {
esbuild: {
options: {
tsconfigRaw: {
compilerOptions: {
target: 'ESNext',
experimentalDecorators: true,
},
},
},
},
},
It partially solves the problem, but unfortunatelly the compilerOptions
property doesn’t receive emitDecoratorMetadata
prop so I get a new error:
(Object literal may only specify known properties, and ’emitDecoratorMetadata’ does not exist in type)
[worker init] Column type for User#id is not defined and cannot be guessed. Make sure you have turned on an “emitDecoratorMetadata”: true option in tsconfig.json. Also make sure you have imported “reflect-metadata” on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.
I’m stuck here, how can I make it work properly?