krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.36k stars 772 forks source link

Unable to configure FuseJS as requireJS module #260

Closed dshastry closed 4 years ago

dshastry commented 6 years ago

We have been using fuseJS to do fuzzy search in a proprietary CRM product. Since it's a large legacy codebase and we have tons of plugins, we use requireJS in order to manage what gets loaded when and for scoping JS. I have not been able to setup Fuse to play nicely with require.

Here's my require config. It's just a simple path that maps to the fuse.min js file in our scripts folder: paths: { fuse: 'fuse.min' },

From looking at the min file, it looks like it's setup to work with an AMD loader like requireJS so i didn't setup a shim or anything else. However, I am unable to get it to work when calling it like so:

require(['fuse'],
            function(fuse) {
//Code here
});

The only way to get Fuse to work with require is by forcing the Fuse variable to attach to window.

require(['fuse'],
            function(fuse) {
window.Fuse = fuse;
//Code here
});

I'd like to avoid this since it circumvents require. Am I missing something or is there a way to get Fuse to load through RequireJS correctly?

Also, Fuse 3.2.1 doesn't seem to work with require, throwing a "Fuse is not a constructor" error. This issue is not seen if reverted to 3.2.0.

Any help would be appreciated!

eliaspn commented 5 years ago

any advancements on this? I couldn't get to work even loading it in global scope. Does anyone encounter the same issue?

kirjeldus commented 5 years ago

I will confirm that I also having this issue in a Magento2 environment (uses requirejs). Also not able to make it work with the global scope hack. Fuse v 3.4.4. Fuse remains undefined although the JS file itself is loaded.

EDIT: https://github.com/krisk/Fuse/issues/178 <- this fixes the problem

github-actions[bot] commented 4 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days