react-minisearch
react-minisearch copied to clipboard
`useMiniSearch` breaks Vite build
There seems to be an issue with the way that useMiniSearch is including MiniSearch in production builds.
Reproduction here: https://stackblitz.com/edit/vitejs-vite-j8sehn
In that reproduction you'll see in the console there is the following error (after it is done building):
u.default.getDefault is not a function
Which is specifically referring to:
var idField = options.idField || MiniSearch__default["default"].getDefault('idField');
If I update the minisearch options to include idField and extractField, it works fine:
import minisearch from 'minisearch'
const options: SearchOptions<SearchItem> = {
fields: ['name', 'email'],
storeFields: ['id'],
searchOptions: {
fuzzy: true,
prefix: true,
},
// fixes build error
idField: 'id',
extractField: minisearch.getDefault('extractField'),
}
This is a fine stop gap solution, but it may be worth investigating why this is not working with Vite. I'm assuming it's due to Vite being an esm based bundler.