7

In a meteor project, I want to pull a few frontend packages. bower can pull many frontend dependencies which are not yet available using meteor add. In many cases, when the meteor packages are available, their versions are lagging behind the official ones, sometimes too behind to consider.

Being a bit of a Meteor newb I've tried to install bower (the most recent meteor bower package I could find):

$ meteor add bozhao:bower

but then, when I run the meteor server it crashes:

W20160110-15:37:57.997(2)? (STDERR) /Users/igal/.meteor/packages/meteor-tool/.1.1.10.7bj3ks++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20160110-15:37:57.998(2)? (STDERR)                         throw(ex);
W20160110-15:37:57.998(2)? (STDERR)                               ^
W20160110-15:37:57.998(2)? (STDERR) ReferenceError: window is not defined
W20160110-15:37:57.998(2)? (STDERR)     at bower_components/leaflet/dist/leaflet-src.js:526:1

Question is: What's the best strategy to install bower and use it in a meteor project? An acceptable answer may show the flow for correctly installing bower, then the leaflet package and it's leaflet.markercluster extension

Sep 27th 2016 edit

The meteor community switched to npm, thus using bower is no longer required. Simply do npm install <package> and import <package> in your client-side code, and you can start using the component!

tivoni
  • 1,990
  • 4
  • 19
  • 37
  • Meteor way is to install package https://atmospherejs.com/bevanhunt/leaflet – 0x860111 Jan 10 '16 at 13:50
  • @0x860111 Yes I'm working with the bevanhunt:leaflet package. I need Leaflet's marker clusters plugin and I couldn't find a (non-experimental) reliable meteor package which provides it. As such I thought maybe reverting to bower can remedy the situation. Do you know about a Meteor clustering plugin I can pull which is compatible with bevanhunt:leaflet? – tivoni Jan 10 '16 at 14:50
  • Did you find any solution ? – Amine Harbaoui Sep 26 '16 at 11:00
  • As I pointed in the update, the meteor community switched to npm, thus using bower is no longer required. Simply do `npm install ` and `import ` in your client-side code, and everything works like a charm! – tivoni Sep 27 '16 at 08:20

1 Answers1

3

meteor search bower turns up a few hits, which I haven't taken the time to compare in any depth. I went with mquandalle:bower as I found it recommended here. Perusing the doc, here is what worked for me:

npm install -g bower                # If not already done
meteor add mquandalle:bower
echo '{ "directory": ".meteor/local/bower" }' > .bowerrc    # If you use bower install --save

Then create a bower.json file at the top of the project tree that reads like this:

{
  "name": "MyApp",
  "version": "0.0.1",
  "dependencies": {
    "leaflet": ">0",
    "leaflet.markercluster": ">0"
  },
  "private": true
}

Re-run your app with meteor run and presto, the stylesheets and JavaScript of your modules are embedded into your page without even having to edit the <head>.

Community
  • 1
  • 1
DomQ
  • 4,184
  • 38
  • 37