3
votes

ember octane tutorial. using: ember generate model person creates a build error when used for person model (and any other model for that matter).

I was looking at the ember octane tutorial and generated the person model. The generated code included code that significantly differs from the example. This extra code causes build errors.

This is after I run

"ember generate model person"

import DS from 'ember-data';
const { Model } = DS;

export default Model.extend({

});

This is the example from https://octane-guides-preview.emberjs.com/release/models/

import DS from 'ember-data';
const { Model, attr } = DS;

export default class Person extends Model {

  @attr('string') firstName;
  @attr('date') birthday;

}

If I added the @attr code to the generated model, I get this build error.

testapp/models/person.js: Unexpected token, expected "," (5:27)
3 | 
4 | export default class Person extends Model ({
5 |   @attr('string') firstName;
  |                            ^
6 |     @attr('date') birthday;
7 | });

The issue was that the generated model includes a few things that the example does not.

export default Model.extend({

instead of

export default class Person extends Model {

I expected a clean build as I used the ember generate model method and added the pieces for the attr as per example.

I think the ember generated model blueprint needs updating for Octane?

I would also suggest the blueprint adds the 'class extends Model' as well?

1
How recently did you create your octane app?NullVoxPopuli
What versions of ember-data and ember-cli-babel do you have?NullVoxPopuli
oh hey, I just noticed your model has paren around the class body. I don't think that's valid?NullVoxPopuli

1 Answers

4
votes

Octane edition is currently in preview (as the guides you linked to indicate) and there is more work to do before it is ready for general use. One of the remaining items is releasing new generator code that matches the guides. Right now the released versions of ember-data include generators for non-octane Ember. There are some ongoing fixes that will be released in ember-data v3.13.0 very soon. This should result in generated models matching your Octane edition expectations.

You can try this out now by running: npm install ember-data@beta

and then re-running your generator ember generate model person.

The other option is just too wait a few weeks while these issues get worked out. Octane is expected to work fully in Ember version 3.14.0.