I have been using Flexsearch for a pretty long time now and it worked amazingly well. That is why I was so surprised when all my tests started to fail with the update to 0.7.43. I pulled down the branch and tried to run it locally. The first thing I noticed was that the build failed because I was doing the following:
import { Document } from "flexsearch";
I changed this to use a default exports as I can see in the source code that it is indeed exported as the default in document.js
import Document from "flexsearch";
However, with that, the following code triggers an error in the developer console:
React.useEffect(() => {
const jsonURL = process.env.REACT_APP_TESTING
? "/tools-test.json"
: "/tools.json";
async function fetchData() {
const response = await fetch(jsonURL);
const tools = await response.json();
setTools(tools);
const index = new Document({ // <<-- THE ERROR IS THROWN HERE
document: {
index: ["tag", { field: "title", tokenize: "forward" }],
},
});
tools.forEach((tool) => {
index.add(tool);
});
setToolsIndex(index);
}
fetchData();
}, []);
Error
TypeError: flexsearch__WEBPACK_IMPORTED_MODULE_1__.default is not a constructor
Any idea why this is happening? I can see that the code in document.js uses new Document itself so curious as to why Webpack is mad. Thanks!
Update: I converted the project to Vite and I am still seeing the same error:
TypeError: Document is not a constructor
at fetchData (App.jsx:53:21)
Hey All,
I have been using Flexsearch for a pretty long time now and it worked amazingly well. That is why I was so surprised when all my tests started to fail with the update to
0.7.43
. I pulled down the branch and tried to run it locally. The first thing I noticed was that the build failed because I was doing the following:I changed this to use a default exports as I can see in the source code that it is indeed exported as the default in
document.js
However, with that, the following code triggers an error in the developer console:
Error
Any idea why this is happening? I can see that the code in
document.js
usesnew Document
itself so curious as to why Webpack is mad. Thanks!Update: I converted the project to Vite and I am still seeing the same error: