Skip to content

Document index + worker in NextJS #522

@artsiompeshko

Description

@artsiompeshko

👋 First of all, thanks for a wonderful alternative to server-baked full-text searches; this library truly performs well.

I could not integrate the document index with the worker enabled inside the NextJS app.

With the below index builder, I am getting Failed to construct 'Worker': Script at ... cannot be accessed from origin, as it tries to resolve worker via file path.

const FlexSearchModule = await import('flexsearch');
  const DefaultEncoder = /* ...  */

  return new FlexSearchModule.Document({
    tokenize: 'forward',
    encoder: DefaultEncoder,
    priority: 2,
    worker: true,
    document: {
      id: 'documentId',
      store: true,
      index: [/* ... */]
    }
  });

I tried several variants to use a string path in the worker property, as I see it can accept it, but could not find a working one.

It seems like webpack 5 expects path to be wrapper with new URL to be working and it does not support variable passing https://webpack.js.org/guides/web-workers/.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions