krisk / Fuse

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

TypeError: n is undefined #343

Closed bin closed 4 years ago

bin commented 4 years ago

This occurs in a react app. Fuse is imported with Import Fuse from "fuse.js";, and I am using version 3.4.6. In a component constructor, I am using the following fuse code:

var options = {
            shouldSort: true,
            tokenize: true,
            findAllMatches: true,
            threshold: 0.6,
            location: 0,
            distance: 100,
            maxPatternLength: 32,
            minMatchCharLength: 1,
            keys: [
                "name",
                "description"
            ]
        };
        var fuse = new Fuse(this.state.imgInd, options);
        var result = fuse.search(params.query);

I get the following error upon npm start:

TypeError: n is undefined  
value
node_modules/fuse.js/dist/fuse.js:188
  185 |     r = {},
  186 |     o = [];
  187 | 
> 188 | if ("string" == typeof n[0]) {
      | ^  189 |   for (var i = 0, a = n.length; i < a; i += 1) this._analyze({
  190 |     key: "",
  191 |     value: n[i],
krisk commented 4 years ago

Should be fixed.