krisk / Fuse

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

TypeError: fuse_js_1.default is not a constructor #529

Closed utsavagrawal closed 3 years ago

utsavagrawal commented 3 years ago

`

import Fuse from 'fuse.js';
let a = ["Utsav Agrawal", "David Agrawal", "Johny Agrawal", "Joseph Agrawal", "Imran Khan"]
const newWord = "Agra";
const opts = {
  threshold: 0.5,
  ignoreLocation: true
}
let result;
try {
  let fuse = new Fuse(a, opts);
  result = fuse.search(newWord as string)
  console.log('result')
  console.log(result)
}
catch (e){
  console.log('errrorrrrrrr')
  console.log(e)
}

`

Getting the above mentioned error.

tsconfig.json>compilerOptions

"compilerOptions": {
    "target": "es6",
    "lib": ["es5", "es6", "dom"],
    "types": ["reflect-metadata", "node", "jest"],
    "outDir": "dist",
    "sourceMap": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "noImplicitAny": false,
    "allowJs": true,
    "preserveWatchOutput": true,
    "resolveJsonModule": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
utsavagrawal commented 3 years ago

This solved the problem for me.

const Fuse = require('fuse.js');

saran1856 commented 2 years ago

Any idea how would this solve the problem for client side services aka web components?

utsavagrawal commented 2 years ago

How are you trying to import it? Did you download a min.js file or was it another way?