2

I'm trying to use Bloodhound and Typeahead in my Browserify project. I'm using browserify-shim.

package.json

{
     ...
    "browserify": {
        "transform": ["browserify-shim"]
    },
    "browserify-shim": "./shim.js",
}

shim.js

module.exports = {
    ...
    'typeahead.js/dist/bloodhound': {
        exports: 'Bloodhound',
        depends: {jquery: 'jQuery'}
    }
};

test.js

...
var Bloodhound = require('typeahead.js/dist/bloodhound');

module.exports = function() {
    console.log(Bloodhound);
}

Which outputs an empty object ({}).

I've followed everything in this relevant question, using vanilla Browserify from the command line, but still no dice.


I was able to get it working by adding

module.exports = Bloodhound;

to the bloodhound.js file, but this is far from ideal. Shouldn't browserify-shim be adding the exports? I didn't see a module.exports for Bloodhound in the generated bundle.js.

Community
  • 1
  • 1
Tucker Connelly
  • 865
  • 1
  • 8
  • 17

1 Answers1

1

Apparently this will be fixed in v0.11 as typeahead.js is moving to the UMD

https://github.com/twitter/typeahead.js/issues/743#issuecomment-52412193

Tucker Connelly
  • 865
  • 1
  • 8
  • 17