flexsearch icon indicating copy to clipboard operation
flexsearch copied to clipboard

The Worker dose not work

Open Keksinautin opened this issue 2 years ago • 1 comments

Hi! Thanks for the lib, but for some reason, the Worker index does not work for me.

What I do:

  1. I create a new project: npx create-react-app test-search --template typescript;
  2. Add the dependency: npm install flexsearch and npm i --save-dev @types/flexsearch;
  3. I clean the src/index.tsx and left there only following code:
import { Worker } from "flexsearch"

const searchIndex = new Worker()
searchIndex.add(1, "some text")

An I see the following error in the browser console:

Uncaught TypeError: Cannot read properties of undefined (reading 'postMessage')
    at flexsearch.bundle.js:22:1
(anonymous) @ flexsearch.bundle.js:22
setTimeout (async)
(anonymous) @ flexsearch.bundle.js:22
P.O.<computed>.O.<computed> @ flexsearch.bundle.js:22
./src/index.tsx @ index.tsx:22
options.factory @ react refresh:6
__webpack_require__ @ bootstrap:24
(anonymous) @ startup:7
(anonymous) @ startup:7

Is it an issue or it is my doing something wrong?

Keksinautin avatar Mar 25 '22 11:03 Keksinautin

the same to me . mark

meiliujun avatar Jul 13 '22 13:07 meiliujun

In Node.js:

const { Worker } = require("flexsearch");

(async function(){

    const worker = new Worker();
    await worker.add(1, "some text");
    console.log(await worker.search("some text"));
}());

As ES6-Module:

import Worker from "./worker/index.js";

(async function(){

    const worker = new Worker();
    await worker.add(1, "some text");
    console.log(await worker.search("some text"));
}());

ts-thomas avatar Oct 03 '22 10:10 ts-thomas