mercredi 26 avril 2017

EmberJS how to solve `Could not find module` when using linked addons

I have a main EmberJS app (AppA) (with routes, models, services...).

Now I would like to create a second app (AppB) which use these models, services ...

On AppA I added the following lines to app/app.js:

engines: {
  appB: {
    dependencies: {
      services: [
        'store'
      ]
    }
  }
}

And in package.json:

  "keywords": [
    "ember-addon"
  ]

I also created the following index.js

/*globals module */

module.exports = {
  name: 'app-a',

  treeForPublic: function(tree) {
    // Return tree as is. This prevents ember-cli from moving the tree to /common.
    return tree;
  },

  // We always want this to be true so that addon files are watched.
  isDevelopingAddon: function() {
    return true;
  }
};

On the AppB side I ran npm link ../app-a and add "app-a": "*" to package.json.

I'm now able to run this.get('store').findAll('product') in a controller of AppB when the model is defined in AppA.

However the model product has a dependency to underscore which is working fine in the AppA app.

But on AppB I'm getting the following javascript error Error: Could not find module underscore imported from app-b/services/store.

Any idea what I'm doing wrong?

I was inspired by http://ift.tt/2pAduYv.




Aucun commentaire:

Enregistrer un commentaire