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

How to properly use worker in the browser mode? #251

Closed
yellow1912 opened this issue Aug 8, 2021 · 7 comments
Closed

How to properly use worker in the browser mode? #251

yellow1912 opened this issue Aug 8, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@yellow1912
Copy link

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.

@rathboma
Copy link

rathboma commented Sep 4, 2021

Having exactly the same issue.

@rathboma
Copy link

rathboma commented Sep 4, 2021

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.

@rathboma
Copy link

rathboma commented Sep 4, 2021

@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

@rathboma
Copy link

rathboma commented Sep 4, 2021

@ts-thomas
Copy link
Contributor

Thanks for this hint. I need to solve the merge conflict before I can merge.

@Gabriel-Alves-Cunha
Copy link

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?

@ts-thomas ts-thomas self-assigned this Oct 2, 2022
@ts-thomas ts-thomas added the bug Something isn't working label Oct 2, 2022
@ts-thomas
Copy link
Contributor

This fix is included in v0.7.23

ts-thomas added a commit that referenced this issue Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants