Typeahead.js: using es6 to import typeahead.bundle.js throws 'Bloodhound' of undefined error

Created on 6 Jan 2017  ·  5Comments  ·  Source: twitter/typeahead.js

problem

like this: Uncaught TypeError: Cannot set property 'Bloodhound' of undefined

image

my way

review the code of typeahead.hundle.js , I found "this" is undefined
image

change "this" to “window”, it works.
image

Most helpful comment

@thatONEjustin I fixed it by adding the bloodhound.js package and using that instead of the one that comes with typeahead. I think that's what @tamanhquyen was suggesting

All 5 comments

You can add Provider in webpack config plugins
new webpack.ProvidePlugin({ jQuery: 'jquery', $: 'jquery', "window.jQuery": "jquery" }),

in source code
import typeahead from "typeahead.js"; import Bloodhound from "bloodhound-js";

@tamanhquyen Thanks! I will try.

already have jquery as a provided plugin through webpack.

still can't get past Cannot set property 'Bloodhound' of undefined

@thatONEjustin : Can you share your sourcecode ?

@thatONEjustin I fixed it by adding the bloodhound.js package and using that instead of the one that comes with typeahead. I think that's what @tamanhquyen was suggesting

Was this page helpful?
0 / 5 - 0 ratings