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.

code minify causes "Entity metadata for e#activities was not found"

See original GitHub issue

Issue type:

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

Database system/driver:

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

TypeORM version:

[ ] latest [ ] @next [x ] 0.2.18

Steps to reproduce or a small repository showing the problem:

@Entity('space')
export default class Space {
  @PrimaryColumn()
  spaceId: string;

  @Column()
  spaceName: string;

  @OneToMany('activity', 'space')
  activities: Promise<Activity[]>
}

@Entity('activity')
export default class Activity {
  @PrimaryColumn()
  activityId: string;

  @Column('text')
  text: string;

  @ManyToOne('space', 'activities')
  @JoinColumn({ name: 'spaceId' })
  space: Promise<Space>
}

In my project, code minifing (uglifyjs) is required, it will convert classnames like ‘Space’ into single characters like ‘e’. The problem occurs here in EntityMetadataBuilder.ts:L649.

IMHO m.givenTableName is not honored but should. Therefore we can use uglifyjs without breaking typeorm.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
bigLucascommented, Feb 17, 2022

Hello guys, I spent a week trying to solve a problem like this. So I solved this problem, just changed my repository method that saves the entity. I used repository.save (entity) and always failed with cyclic dependency.

After switching to

repository.createQueryBuilder()
    .insert()
    .into(TABLE_NAME)
    .values(entity)
    .execute();

This error has been cleared. I really recommend trying to change the repository method, because the save() method waits for the full entity set and createQueryBuilder() takes the entity values and turns them into string values, making a normal query.

I was using serverless and webpack. Typeorm does not work well with webpack.

1reaction
cvdat2097commented, Apr 29, 2022

My Solution

Just declare unique static property name for each of your classes image

How does this fix the “Cyclic dependency” error of minified code?

This error derives from function SubjectTopoligicalSorter.toposort() which requires unique targetNames. Those targetNames are extracted from the special property Function.name of our classes (yes, classes are functions in JS). However, after the minification process, the class names (function names) are changed to something like “t”, “e”,… which can be duplicated. Therefore, manually assign unique name values for our classes solved the problem.

Bonus Solution

You can configure the bundler not to touch the function names to fix this. However, I personally don’t prefer this method. Take my metro.config.js file for example (I’m using typeorm in React Native project)

module.exports = {
  transformer: {
    minifierConfig: {
      keep_fnames: true, // To avoid cyclic dependency "t" error of typeorm in release build
    },
  },
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity metadata for Role#users was not found - Stack Overflow
Trying to make OneToMany and ManyToOne relationship with TypeORM but I get this error, I don't know what's wrong with my code. I...
Read more >
typeormerror: entity metadata for was not found. - You.com
It seems strange that the error says "Unable to connect to the database", but the error causing that seems to be thrown in...
Read more >
Federal Register/Vol. 71, No. 194/Friday, October 6, 2006
The FEDERAL REGISTER (ISSN 0097–6326) is published daily,. Monday through Friday, except official holidays, by the Office.
Read more >
handling exclusion zone: Topics by Science.gov
This article describes the localization and characteristics of the radioactive waste present in the Chernobyl Exclusion Zone and summarizes the pathways and ...
Read more >
On the Perceptions of Online Learning Due to COVID-19 ...
Find, read and cite all the research you need on ResearchGate. ... refer to the 'metadata' regarding author credentials, which may not receive...
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