-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If you have problems with the default typings on 0.7.31 or with the index.export
method, check this
#406
Comments
Thanks for the tips. If
That said there are also other breaking changes in the recent versions, so just doing this won't save you from the headache. E.g. for the "async" export I did
but ultimately, I stuck to 0.7.21 and will probably patch as well. |
Thanks! I didn't know you could override types like that. If the After creating the patch, I run into some other problem which I don't remember now with 0.7.31 (as you said, this doesn't save from all the headaches) and ended up rolling back again to 0.7.21. I also created a patch for that version so I could use the In case anyone needs it, you can find it here. Version 0.7.21 does not come with default breaking types, so this patch doesn't need to handle that, it only fixes the |
This package is so crooked that you're better off using another one. There are plenty of them. |
@Pilaton can you point out some alternatives? I've been looking around and I've not found one that can replace the way I'm using Thanks in advance. |
@iivvaannxx I recently merged some PRs, can you check please if something is missing? |
@ts-thomas I've done a couple of tests on a new project. At the moment I can confirm that the type declaration files are not picked out of the box, after installing The module is still a import { Index } from 'flexsearch' If you try it Vite will complain with the following error:
And if you import it as the error says it works. But, the import FlexSearch from "flexsearch"
import type { PageServerLoad } from "./$types"
export const load: PageServerLoad = async ({ fetch }) => {
const response = await fetch('src/options.json')
const fileContent = await response.json() as any[]
const { Index } = FlexSearch
const options = new Index({
preset: 'performance',
tokenize: 'reverse',
cache: 200
})
fileContent.forEach((option, index) => {
options.add(index, option.name)
})
const dataIndex = { }
await options.export((key, value) => {
console.log("Exporting", key)
Object.assign(dataIndex, { [key]: value })
})
console.log("Export Done!")
return dataIndex
} This is a simple snippet I made on a brand new SvelteKit project just to test the package as I was asked. The file
|
Disregard that. A Promise should be returned at all times when calling @ts-thomas, I'm not seeing the new code under |
@iivvaannxx we need to have both, ESM support and Node.js support, so thats why they exist 2 different builds. That is what I have actually in package.json
Node.js will pick "main" by default, so here it is a CommonJS export, used by Node.js as default. https://github.com/defunctzombie/package-browser-field-spec |
@thexeos I will make a new build later today. Actually I'm updating the whole build stuff. |
Also please take a look here: #417 It isn't online yet, but is coming later today. There are 2 versions of ESM modules:
Which of both is better for the "browser" field in the package.json and which one is better for "main"? |
If you can make the bundled one be exposed as a separate module of the package (see below), then you can default to granular (non-bundled) export with appropriate types. {
"type": "module",
"exports": {
".": {
"main": "dist/flexsearch.non-bundle.js",
"browser": "dist/flexsearch.non-bundle.js",
"module": "dist/flexsearch.module.non-bundle.js",
"types": "dist/flexsearch.non-bundle.d.ts"
},
"bundle": {
"main": "dist/flexsearch.bundle.js",
"browser": "dist/flexsearch.bundle.js",
"module": "dist/flexsearch.module.bundle.js",
"types": "dist/flexsearch.bundle.d.ts"
}
}
} Although, I'm not sure this is the most elegant solution, as it leads to a different question: why is bundled even included in the "exports"? If bundled file is only ever used via direct reference in the browser (no bundlers involved), then it can be linked directly via full path ( Node.js resolver would be happy to navigate the file-system and load individual (non-bundled) files. The penalty is only incurred at startup and with the size of an average |
It seems that this repository is no longer maintained. It didn’t receive any commits in the whole year except for one, on July which only modified the README to include some donation links.
The latest version left the package in an unusable state with Typescript, because it ships with a set of wrong types. The correct ones are located at DefinitelyTyped, so you need to install
@types/flexsearch
. The problem is that they are overriden by the default typings. At the end of this issue you will find a patch to remove these default types.Also, there's the
index.export
function which is typed as anasync
function because it’s supposed to be async, but it’s actually not. It runs “asynchronously” but it doesn’t return a Promise, so you can’t await the method to finish. See: #353 and #393.With the PR #374 (thanks! @thexeos), I created a patch file using
pnpm patch
after rebuilding the package from source using the fix. In my case it is installed by copying it to apatches
folder at the root directory of my project and modifying thepackage.json
like this:But it should also work with
patch-package
. You can find the patch here. After installing it you should be able toawait
theindex.export
method. If you are only interested in removing the typings you can use only this specific part from the patch:I hope this can be useful, it solved my problems with both bugs in a fresh project I tested it on.
The text was updated successfully, but these errors were encountered: