Moving Ember data models into a js module

Hi all,

Just wondering if anyone has had experience moving ember data models into a module? The use case is that I’m trying to DRY-up codebase where a webapp and Ember addons all share the same models.

Thanks for any help or pointers!


You’ll need to re-export all the models in the host’s app directory. V2 addons make this pretty easy and nice.

Near term schemas are the better answer. Keep an eye out for when we ship SchemaModel and the Schema parser


Thanks for your help!

Most of my issue was actually attempting to create it as a very naive ES6 module.

Actually now just stuck on the re-export. Naively doing this in the application model:


import UserModel from 'my-ember-models/addon/models/user';

export default UserModel;

And it’s blowing up at runtime:

Could not find module `my-ember-models/addon/models/user` imported from `webapp/models/user`

Any thoughts? Assuming I’m doing something a little silly.

I think you just need to remove “addon” from the import path. In v1 addons the fs location doesn’t match the module lookup path so lookup path is “my-addon-name/models/model-name”

So this turned out to actually be a typescript issue! Forgot to generate the definitions for the addon! :rofl: