vkurchatkin / which-country

Get ISO 3166-1 alpha-3 country code for geographic coordinates
56 stars 28 forks source link

Rbush error when using wc with browserify #1

Closed mvpasarel closed 9 years ago

mvpasarel commented 9 years ago

I have a backbone app where I tried using this module + browserify. The grunt browserify command setup is :

    grunt.config.set('browserify', {
        wc: {
              src: './node_modules/which-country/lib/which-country.js',
              dest: './client/scripts/which-country.js',
              options: {
                require: ['rbush', 'point-in-polygon'], 
              }
            },
      });

I tried also :

    grunt.config.set('browserify', {
        wc: {
              src: './node_modules/which-country/index.js',
              dest: './client/scripts/which-country.js',
            },
      });

And in my location/add.js Backbone view file I use:

var wc = require('which-country');
console.log(wc([37, 55]));

But I get the same errors:

Uncaught TypeError: rbush

Uncaught TypeError: wc is not a function

Do you have any idea what I am doing wrong or how should I use this with backbone+requirejs?

vkurchatkin commented 9 years ago

So is it browserify or requirejs? I'm not sure about requirejs, but provided example is compiled with browserify just fine, see https://github.com/vkurchatkin/which-country/blob/master/package.json#L10

mvpasarel commented 9 years ago

I am not sure either, perhaps its requireJS. I compiled it to using browserify, using grunt and without cssify. Would that be a problem as long as I dont use the css?

Anyway, rbush seems to be working with requirejs after I compile it with browserify just as in my example with grunt so maybe there are some compatibilities added more for requirejs in rbush. I will check it out and maybe make a PR for this with requirejs.

vkurchatkin commented 9 years ago

not a problem, cssify is just used for example. If you actually want to use which-country with require.js the best way probably is to compile it to UMD with browserify.

mvpasarel commented 9 years ago

I didnt managed to make it work with requirejs. I ended up copying the files into a requirejs local file. Thank you for the package and help :+1: