patternjavascriptCritical
TypeError: Class extends value undefined is not a function or null
Viewed 0 times
classundefinednullfunctionextendstypeerrornotvalue
Problem
I am getting the following error when trying to create these entities.
I am assuming this has something to do with circular dependencies, but how is that supposed to be avoided when using table inheritance and one to many relationships?
It is complaining about the following javascript at
Here is the complete file.
```
import {Entity, Column, PrimaryGeneratedColumn, OneToMany} from "typeorm";
import {Comic} from "./Comic";
@Entity()
export class Series {
@PrimaryGeneratedColumn()
public id: number;
@Column("text", {
length: 30
})
public copyright: string;
@Column("text", {
length: 100
})
public attributionText: string;
@Column("text", {
length: 150
})
public attributionHTML: string;
@Column("text", {
length: 50
TypeError: Class extends value undefined is not a function or nullI am assuming this has something to do with circular dependencies, but how is that supposed to be avoided when using table inheritance and one to many relationships?
It is complaining about the following javascript at
BaseComic_1.BaseComic.let Variant = class Variant extends BaseComic_1.BaseComic {Here is the complete file.
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c = 0; i--) if (d = decorators[i]) r = (c 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const typeorm_1 = require("typeorm");
const Comic_1 = require("./Comic");
const BaseComic_1 = require("./BaseComic");
let Variant = class Variant extends BaseComic_1.BaseComic {
};
__decorate([
typeorm_1.ManyToOne(type => Comic_1.Comic, comic => comic.variants),
__metadata("design:type", Comic_1.Comic)
], Variant.prototype, "comic", void 0);
Variant = __decorate([
typeorm_1.ClassEntityChild()
], Variant);
exports.Variant = Variant;
//# sourceMappingURL=Variant.js.map```
import {Entity, Column, PrimaryGeneratedColumn, OneToMany} from "typeorm";
import {Comic} from "./Comic";
@Entity()
export class Series {
@PrimaryGeneratedColumn()
public id: number;
@Column("text", {
length: 30
})
public copyright: string;
@Column("text", {
length: 100
})
public attributionText: string;
@Column("text", {
length: 150
})
public attributionHTML: string;
@Column("text", {
length: 50
Solution
I was having the same issue. It turns out I was circularly importing classes, which is apparently a limitation. (See these GitHub issues: #20361, #4149, #10712)
Note that it seems that the circular reference is also limited between files, not simply types.
See this other answer
Note that it seems that the circular reference is also limited between files, not simply types.
See this other answer
Context
Stack Overflow Q#43176006, score: 325
Revisions (0)
No revisions yet.