question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum not resolved if it is from an external file

See original GitHub issue

Issue type:

[ ] question [x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [x] mysql / mariadb [ ] oracle [ ] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I am using nestjs, I have defined an enum in an entity and used there. I needed to use it also in another entity, however, using an import typeorm seems to not resolve it.

In my file order.entity.ts I define

export enum OrderStatus {
    placed = "placed",
    paid = "paid",
    confirmed = "confirmed",
    shipped = "shipped",
    completed = "completed",
    cancelled = "cancelled"
}

@Entity()
export class Order extends BaseEntity {
    @PrimaryGeneratedColumn("uuid")
    id: string

    @IsNotEmpty()
    @Column({ type: "enum", enum: OrderStatus })
    status: OrderStatus
}

and in the issue entity order-product.entity.ts I write:

import { OrderStatus } from "./order.entity";

@Entity()
export class OrderProduct extends BaseEntity {
    @PrimaryGeneratedColumn("increment")
    id: number

    @IsNotEmpty()
    @Column({ type: "enum", enum: OrderStatus })
    status: OrderStatus
}

The resulting query is CREATE TABLE `order_product` (`id` int NOT NULL AUTO_INCREMENT, `status` enum NOT NULL, PRIMARY KEY (`id`)) producing an sql error as the enum is not defined. The error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL, PRIMARY KEY (`id`))' at line 1

Defining the enum also inside the orderProduct entity file the enum is resolved and the query is executed correctly.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

3reactions
AlexMessercommented, Jul 24, 2021

Okay, I checked @jeznag and know what is the issue. The issue is in JavaScript runtime behavior. You are circular referencing files, and ActionMeta is importing Action while Action imports ActionMeta. And unlucky enum is undefined in this circular mess. While classes somehow work (also using “hacks”, like () => ClassDefinition), it looks like this is a dead case for enum. Such circular references always bring problems.

To ensure I’m right, just console.log() your enum inside ActionMeta after class definition.

This issue can’t be resolved, because it’s related to JavaScript runtime behavior. Solution: extract enum to a separate file with only enum(s) definitions.

0reactions
cronnoslicommented, Jul 14, 2021

This behaviour happens here as well. While in version 0.2.29 this was not happening, recently we upgraded to 0.2.34 and it is impossible to run migration:generate without duplicating the enun in each entity that uses it.

I found that the isArraysEqual method on this case passes the first enum array as undefined, while the second one is correct. As undefined is different than an array this method fails.

This bug affects also [X] postgres

Read more comments on GitHub >

github_iconTop Results From Across the Web

The type java.lang.Enum cannot be resolved - Getting error ...
I am getting the following error after importing Java project (Non Maven) in Eclipse: The type java.lang.Enum cannot be resolved.
Read more >
enum external declaration and use - Keil forum
Hi Folks, I am trying to use enum to define a set of named constants with values so that they can be used...
Read more >
Build Enumerations of Constants With Python's Enum
In this tutorial, you'll learn how to create and use enumerations of semantically related constants in Python. To do this, you'll use the ......
Read more >
Import of enumeration type cannot be resolved in service
to the pregenerated Services.java file yields the error: "The import <model-package>.MyEnumType cannot be resolved." Importing classes that ...
Read more >
Chromium Docs - Accessing C++ Enums In Java
Symbol not found/could not resolve IntDef ... are prefixed with the MACRO_CASED_ name of the enum those prefixes will be stripped from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found