flexsearch
flexsearch copied to clipboard
How to properly use worker in the browser mode?
Hello,
I'm trying to use this module in the browser. I'm using the following code according to the doc:
const { Worker } = require("flexsearch");
var myWorker = new Worker();
When I try the search, myWorker.search('some test'); I get the following error:
"TypeError: Cannot read property 'postMessage' of undefined at eval (webpack://@somepath./node_modules/.pnpm/[email protected]/node_modules/flexsearch/dist/flexsearch.bundle.js?:23:229)"
I'm using Webpack to build my package, it seems like I missed something obvious but I cannot figure out what.
Having exactly the same issue.
This issue seems to be this line:
https://github.com/nextapps-de/flexsearch/blob/master/src/worker/index.js#L43
I'm running in Electron, and this is incorrectly identifying the process as a node process. It's not.
@ts-thomas Could this line use the following check instead?
if (typeof window === 'undefined')
// this is node
In an electron window with nodeIntegration
enabled it will look like a node process, but actually needs to be a browser process
See code here - https://github.com/flexdinesh/browser-or-node/blob/master/src/index.js
Thanks for this hint. I need to solve the merge conflict before I can merge.
Is this a solved issue?? Cause I've been having the same issue and I'm using version 0.7.21 In the meantime, is there a way to get around this?
This fix is included in v0.7.23