Skip to content
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

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

Open
timmeno1 opened this issue Nov 27, 2022 · 7 comments
Open

Comments

@timmeno1
Copy link

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
Copy link
Owner

lucaong commented Nov 27, 2022

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
Copy link

DavidRouyer commented Dec 13, 2022

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
Copy link

Same issue with 5.0.0-beta2, lucaong/minisearch@39d2697 must be the culprit

@lucaong
Copy link
Owner

lucaong commented Dec 13, 2022

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
Copy link

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
Copy link
Owner

lucaong commented Dec 13, 2022

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

@nawazish0230
Copy link

nawazish0230 commented Jan 10, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants