I took a few minutes and checked things out in your demo repo (thanks for putting that together!), here is a relative brain dump of what is going on here.
In Ember 3.2, the internals of .extend() were changed to better support ES class interoperability. This was specifically intended to fix the exact scenarios that you are running into, and we have tests to confirm this back and forth (.extend() → class extends → .extend() → class extends ) works properly both with and without transpilation!
Unfortunately, the way Ember is distributed (as a pre-transpiled global bundle) means that we ended up in a scenario that we didn’t test or plan for . The fundamental issue is that the class interop code that was done in Ember 3.2+ ends up being transpiled away by babel (since Ember is transpiled to support IE11), and instead of the Ember object base class calling super as appropriate it is using the transpiled version (BaseConstructor.call(this)) which causes errors.
Also, to be clear the errors being thrown are unrelated to ember-decorators or ember-data. The following also reproduces the issue:
class Foo extends Ember.Object {}
class Bar extends Foo.extend() {}
Bar.create();
To work around the issue for now, you can change your code to ensure that you do not call .extend() on anything created by class extends. The example above would look like:
class Foo extends Ember.Object {}
class Bar extends Foo {}
Bar.create();
The real fix will have to be made in Ember itself where we need to change things to ensure that Ember is transpiled in the same way as your app code.
Hope all this makes sense, and I’m sorry for the issue .
Thanks a lot for taking the time to investigate and to write down this answer! All this is very enlightening.
Since this seems to be a bug in Ember itself, do you need me to file an issue or have you done this already?
As far as my project is concerned, I cannot work around this by removing .extend() because I need it for a polymorphic hasMany relationship. See my other post about this:
Polymorphic hasMany relathionship with ES6 classes.
Others might also need .extend() to include mixins. I guess the right solution for the time being is to rewrite the super class without the ES6 class syntax;
@bartocc, @rwjblue - was this ever fixed? I just hit the same issue on Ember 3.5.0. We have a:
export default class Model extends EmberObject {
And then we do:
let x = Model.extend(...mixins, properties)
And then calling “new x()” blows up with the same error. Is there an issue on the issue-tracker I can subscribe to? Was this fixed? Did it break again?
If in your app you want to just apply mixins to your native class you could do
export default class Model extends EmberObject {}
Model.reopen(...mixins, properties);
which is the same as extend() but now babel will transpile the class extends the same as your app, so if babel-preset-env supports your target it will keep it.