Though it might be obvious to many, it was a bit frustrating when my friend and I could not get "import Fuse from 'fuse'" to work.
The official way should be I guess "import Fuse from 'fuse.js'"
I know it might be obvious, but can we just put this in readme.md and also the description on the npm site? Thanks!
This should work:
import * as Fuse from 'fuse.js';
import * as Fuse from 'fuse.js';
Doesnt work
new Fuse(collection, options) => Error Fuse is not a constructor
This one will work
import Fuse from 'fuse.js';
None of the above worked for me, but this notation did:
import Fuse from 'fuse.js/dist/fuse.min.js';
still a problem for me.
const index = Fuse.createIndex<MyType>(
keys: ['key1', 'key2']
list: list
)
is refused.
I also think there appears to be a problem here.
import * as Fuse from 'fuse.js' satisfies the type checker but throws TypeError at runtime in v5.1.0 when instantiating a Fuse object: fuse_js__WEBPACK_IMPORTED_MODULE_0__ is not a constructor.
Not an expert but I suspect this is happening because the Fuse constructor clashes with the Fuse namespace?
One ugly workaround in TypeScript 2.7 or later is to use default import by enabling allowSyntheticDefaultImports and esModuleInterop and switching to import Fuse from 'fuse.js'. But I wish you can provide some advice on the right fix? This was not an issue in v3.4.5.
I also think there appears to be a problem here.
import * as Fuse from 'fuse.js'satisfies the type checker but throws TypeError at runtime in v5.1.0 when instantiating a Fuse object:fuse_js__WEBPACK_IMPORTED_MODULE_0__ is not a constructor.
Not an expert but I suspect this is happening because the Fuse constructor clashes with the Fuse namespace?
One ugly workaround in TypeScript 2.7 or later is to use default import by enablingallowSyntheticDefaultImportsandesModuleInteropand switching toimport Fuse from 'fuse.js'. But I wish you can provide some advice on the right fix? This was not an issue in v3.4.5.
Thanks, this did the trick for me when nothing else did.
Update: It seems what I reported earlier is also reported in #384 and investigated in: https://github.com/angular/angular-cli/issues/17393. If the proposed fix is reasonable to you, I volunteer to make the change.
Should be fixed as of fuse.[email protected]: https://github.com/krisk/Fuse/issues/384
You can import normally: import Fuse from 'fuse.js.
Thank you @krisk for cutting a release so fast!
if anyone got this error fuse_min_js_1.default is not a constructor import fuse like this
var Fuse = require('fuse.js');
@krisk I still have a problem with latest version (5.2.3):
import Fuse from 'fuse.js';
and here is my tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"incremental": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"suppressImplicitAnyIndexErrors": true,
"noImplicitAny": true,
"skipLibCheck": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": false,
"strictNullChecks": false,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"removeComments": true,
"baseUrl": ".",
"paths": {
"*": ["node_modules/*"]
},
"typeRoots": ["typings", "node_modules/@types"]
},
}
I'm getting the following error: TypeError: fuse_js_1.default is not a constructor
It's working as of 6.0.0 馃憤 @kikar how's the upgrade working for you?
import * as Fuse from "fuse.js" is _not working_. That's not a problem, but many examples I saw, including at the top of this issue, used that approach and it's not (no longer?) correct.
import Fuse from 'fuse.js'; is not working in version 6.0.0 for me.
If it's working for you @kbpontius, can you share your tsconfig.json and how you import it?
Most helpful comment
import Fuse from 'fuse.js';is not working in version 6.0.0 for me.If it's working for you @kbpontius, can you share your
tsconfig.jsonand how you import it?