Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if compiled with "compilerOptions" - "target": "es6" #1

Closed
extart opened this issue Nov 9, 2017 · 18 comments
Closed

Error if compiled with "compilerOptions" - "target": "es6" #1

extart opened this issue Nov 9, 2017 · 18 comments
Assignees

Comments

@extart
Copy link

extart commented Nov 9, 2017

Compilation is successful, but when starting on the device, an error occurs - main.js: 7 Uncaught ReferenceError: Author is not defined
How to compile the project under ECMAScript 6?

@daniel-lang
Copy link
Contributor

I'm not sure webpack or ionic fully support ES6 yet. May I ask why you need to run your app with ES6?

@extart
Copy link
Author

extart commented Nov 15, 2017

Ionic support ES6. My applications on Ionic are compiled under ES6, except for the use of TypeORM. Applications under the ES6 are much easier to debug if you use async/await. And, as far as I can see, they work a little faster, the interface is more responsive.

@extart
Copy link
Author

extart commented Nov 15, 2017

TypeOrm generally supports the ES6?

@daniel-lang
Copy link
Contributor

TypeORM should support ES6 but the compiled version in the package uses ES5. I haven't tried running the app or TypeORM with ES6

@pleerock
Copy link
Member

TypeOrm generally supports the ES6?

Of course typeorm supports es6.

TypeORM should support ES6 but the compiled version in the package uses ES5.

that should be zero issues with it compiled into es5 since es6 includes all features which present in the es5, right.

main.js: 7 Uncaught ReferenceError: Author is not defined

@extart create a demo repository for @daniel-lang and check the issue together since I dont have ionic stuff installed and not an expert in this area. Also provide a detailed error with code example, how do we know what is Author is not defined ? Where Author is not defined? Do you have circular relations?

@daniel-lang
Copy link
Contributor

@pleerock I can recreate the issue as @extart just tries to compile this example with es6. The error occures when trying to access the Author entity which, since it's es6, is a class.
I don't know, why this error occures as es6 classes are supported by all major browser...

@extart
Copy link
Author

extart commented Nov 16, 2017

If you run this example in Chrome (the command is "ionic serve"), then the same error occurs.

@daniel-lang
Copy link
Contributor

Do you have a working Ionic example (without TypeORM) that works with ES6 and that you can share?

@extart
Copy link
Author

extart commented Nov 18, 2017

I will prepare a working example and put a link here.

@extart
Copy link
Author

extart commented Nov 20, 2017

A working example is the standard Ionic example.
https://github.com/ionic-team/starters/tree/master/ionic-angular/official/super
Change to tsconfig.json "target": "es6" and run.
Everything works and if you look at the main.js, you can see the classes.
If you add TypeORM in this example, an error occurs.

@extart
Copy link
Author

extart commented Nov 21, 2017

@daniel-lang, Is there a chance to fix it?

@daniel-lang
Copy link
Contributor

@extart I finally had enough time to dive into this problem. It seems like it's exactly what @pleerock suspected in the beginning.

Do you have circular relations?

After removing the import statement from author.ts that loads post.ts the demo is compiled under es6. But this means, that the ManyToOne relation only works on one side. Checkout the es6 branch for the changes that I had to make and see with that works for you.

@daniel-lang daniel-lang self-assigned this Nov 21, 2017
@extart
Copy link
Author

extart commented Nov 21, 2017

@daniel-lang Indeed, when I removed the circular relationship, it all worked. I checked in my project. In general, the problem is solved, but you probably need to somehow write about this feature in the documentation for TypeORM...
Thank you so much!

@daniel-lang
Copy link
Contributor

I would assume, that this is not a TypeORM specific problem but rather a problem of es6 with webpack. But it might be an issue to add it to the faq, @pleerock, that do you think?

@extart Can this issue be closed now?

@extart
Copy link
Author

extart commented Nov 22, 2017

@daniel-lang I think you can close this issue. Once again many thanks!

daniel-lang pushed a commit that referenced this issue Feb 27, 2018
@ppulwey
Copy link

ppulwey commented Mar 7, 2019

I have the same issue when I try to use typeorm in connection with vue / electron.
The solution to remove the ManyToOne decorator works but is not ideal.
Is there any chance this will be fixed in the near future?

@shareef-sulopa
Copy link

The problem still exists. The manyToOne relationship is not working when compiled with webpack. I just can't remove the relationship.

@shareef-sulopa
Copy link

shareef-sulopa commented Apr 10, 2019

Got it working when I have changed to

@Entity()
export default class User {} 

From

@Entity()
export class User {} 

Added "default" export in the entity

AND

imported like this

import User from './User';

Instead of
import {User} from './User';

There was a problem with webpack dealing with circular dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants