react-minisearch icon indicating copy to clipboard operation
react-minisearch copied to clipboard

Uncaught TypeError: MiniSearch__default.default is not a constructor

Open timmeno1 opened this issue 2 years ago • 7 comments

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

timmeno1 avatar Nov 27 '22 20:11 timmeno1

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.

lucaong avatar Nov 27 '22 22:11 lucaong

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 avatar Dec 13 '22 09:12 DavidRouyer

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

DavidRouyer avatar Dec 13 '22 09:12 DavidRouyer

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?

lucaong avatar Dec 13 '22 12:12 lucaong

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 },
  });
  ...
}

DavidRouyer avatar Dec 13 '22 12:12 DavidRouyer

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

lucaong avatar Dec 13 '22 18:12 lucaong

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

nawazish0230 avatar Jan 10 '23 07:01 nawazish0230