Nathan Friedly
Nathan Friedly

Reputation: 8146

How do I get my ember.js app to import modules installed from bower or npm

I'm pretty new to some of this stuff and I feel like I must just be missing something simple. I have a very basic Ember.js app that I created with the CLI tool flowing the guide. The code is at https://github.com/nfriedly/particle-webhook-manager

It has a couple of routes and components, and a single third-party dependency, particle-api-js. I installed it twice, via bower and npm, and I'm importing it in one of my components like so:

import particle from 'particle-api-js';

I start up my server with ember serve and it builds successfully. I then open my browser to http://localhost:4200/login where I load the component and it gives me the following error in my console:

Error: Could not find module `particle-api-js` imported from `particle-webhook-manager/components/login-form`

So, my main question is: what am I doing wrong here/how do I make it work?

My secondary question is: why did it "build" successfully and then throw a runtime error for the missing module - shouldn't it have found that in the build stage?

Upvotes: 1

Views: 916

Answers (1)

Lux
Lux

Reputation: 18240

You should not use bower anymore. Use ember browserify to import things installed with npm.

You can import bower modules in your ember-cli-build.js with app.import('bower_components/...js').

You can not import them directly, but you can create a vendor shim to provide this for you. Checkout the ember-cli documentation for this.

Upvotes: 3

Related Questions