lucaong / react-minisearch

React integration for the MiniSearch client side full-text search library
MIT License
45 stars 8 forks source link

Uncaught TypeError: MiniSearch__default.default is not a constructor #33

Open timmeno1 opened 1 year ago

timmeno1 commented 1 year ago

Hello, i'm caused by "Uncaught TypeError: MiniSearch__default.default is not a constructor" when just trying to initialize const { search, searchResults } = useMiniSearch(documents, miniSearchOptions) doing same as provided in examples. May be i'm doing wrong? p.s. sorry for my english

lucaong commented 1 year ago

Hi @timmeno1 , are you using TypeScript? If so, you might need to set the esModuleInterop option to true in the compilerOptions section of tsconfig.json.

DavidRouyer commented 1 year ago

I have the same problem with v5.0.0 (v5.0.0-beta1 is working fine), my esModuleInterop flag is already true 😢

Uncaught TypeError: MiniSearch__default.default is not a constructor
    at useMiniSearch (react-minisearch.tsx:23:1)
DavidRouyer commented 1 year ago

Same issue with 5.0.0-beta2, https://github.com/lucaong/minisearch/commit/39d269740fd21fc46b3980c916fd35bf49acfe77 must be the culprit

lucaong commented 1 year ago

What is strange is that the examples in this repo are working fine, and so the projects where I use this library. I think I need some more info to debug this. For example, how do you import react-minisearch?

DavidRouyer commented 1 year ago

Are you using the https://create-react-app.dev/?

import { useMiniSearch } from 'react-minisearch';

export const MyComponent: React.FC = () => {
  ...
  const { search, searchResults, addAll, removeAll } = useMiniSearch<{
    id: string;
    name: string;
  }>([], {
    fields: ['name'],
    storeFields: ['name'],
    searchOptions: { prefix: true },
  });
  ...
}
lucaong commented 1 year ago

I don’t, but I can try it to reproduce the issue

nawazish0230 commented 1 year ago

I am also facing the same issue with version 6.0.2, and esModuleInterop is also true