code minify causes "Entity metadata for e#activities was not found"
See original GitHub issueIssue 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:
- Created 4 years ago
- Reactions:1
- Comments:17 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.
My Solution
Just declare unique static property
name
for each of your classesHow does this fix the “Cyclic dependency” error of minified code?
This error derives from function
SubjectTopoligicalSorter.toposort()
which requires uniquetargetName
s. ThosetargetName
s 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)