7

I'm trying to create my first Ember AddOn and I'm getting stuck importing it into an Ember project. I've created the addon and published to github like this:

ember-cli$ ember addon test-addon
ember-cli$ cd test-addon
ember-cli/test-addon$ git remote add origin <github-url>

Then, from my project, I install the addon:

test-app$ ember install <github-url>

And, lastly, try to import it into a route:

# app/rotues/index.coffee
import TestAddon from 'test-addon'

But, I'm getting this error on the console:

Uncaught Error: Could not find module `test-addon` imported from `test-app/routes/index`

Any ideas where I'm going wrong? I can see the addon in the node_modules directory but not in bower_components. I think(tm) this is my issue but I'm not sure what else I need to do to setup my addon.

spinlock
  • 3,737
  • 4
  • 35
  • 46
  • 3
    If you're not publishing to npm, you must [link](https://docs.npmjs.com/cli/link) your addon to your ember project – MilkyWayJoe May 26 '15 at 20:06
  • Thanks @MilkyWayJoe but I don't think that's the problem. I'm publishing the addon to a private repo on github then installing it in the test-app (I added the install step to my question). I've also tried npm link as you suggested but I still get the same error. – spinlock May 26 '15 at 21:02

1 Answers1

17

tl;dr

cd my-addon
npm link
cd /my/project/dir
npm link my-addon
ember g my-addon  # run default blueprint

Then add "my-addon": "*" to the devDependencies section of your app's package.json and restart the ember-cli app server.

Longer Answer

The easiest way to include a locally-developed addon is to use NPM's link

First run npm link from the root of your addon project to register it with npm. Then running npm link <your-addon-name> will have the same effect as npm installing it.

You'll still need to manually add it to your package.json (required for ember-cli to find it when compiling your app) and run the default blueprint (if your addon has one).

If this doesn't seem to be working, check that you've created a package.json in your addon with "ember-addon" in the keywords list (the default ember-cli addon blueprint should do this for you).

Liam
  • 27,717
  • 28
  • 128
  • 190
Gabriel Grant
  • 5,415
  • 2
  • 32
  • 40
  • I'm going to accept this as the answer because using a local repo is definitely the way to go. I forget what was wrong with importing from github but it's definitely easier to keep the addon local. – spinlock Nov 10 '15 at 17:41
  • Yes, certainly for development, linking is the way to go. But if you're building somewhere else (CI or something), then I'm fairly certain you should just be to install from a private repo the same as normal... Anyway, glad you got it sorted out! – Gabriel Grant Nov 12 '15 at 05:37