Class Constructor TypeOrmCrudService Cannot Be Invoked Without ‘New’ Error
Cause
Recently I was developing a chatgpt gateway project using nestjs, with nestjsx-crud to speed up curd development, and I had the following code:
1
2
3
4
5
6
7
8
|
@Injectable()
export class ChatgptAccountService extends TypeOrmCrudService<ChatGPTAccount> {
constructor(
@InjectRepository(ChatGPTAccount)
private readonly chatgptAccountRepository: Repository<ChatGPTAccount>,
) {
super(chatgptAccountRepository);
}
|
At runtime it threw the error:
1
|
Class Constructor TypeOrmCrudService Cannot Be Invoked Without 'New'
|
Solution
I looked it up online and found one here: For anyone stumbling over this issue: it's probably a tsconfig issue. Try bumping your target from es5 to es6.
Let me look at my project’s tsconfig.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
{
"compilerOptions": {
"lib": [
"es5",
"es6"
],
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true
}
}
|
And compare it with a project that used to work:
1
2
3
4
5
6
7
8
9
10
11
|
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
...
|
Changing target to es2017 fixed it:
1
2
3
4
5
6
7
8
9
10
11
|
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true
}
}
|