Function process.hrtime.bigint() not found, when used inside a Web Worker
tommy4st opened this issue · comments
Describe the bug
I cannot use Orama inside a Web Worker in Firefox and/or Chrome because it uses process
, which is somehow defined, but doesn't supply the function bigint()
.
To Reproduce
Just do a simple search inside a Worker, like in this example:
import { create, search, insert } from 'https://cdn.jsdelivr.net/npm/@orama/orama@2.0.0-beta.12/+esm';
async function wrap() {
const db = await create({
schema: {
title: 'string',
}
});
await insert(db, { id: '1', title: 'Hello World' });
return await search(db, { term: 'World' });
}
wrap().then(res => postMessage(res));
You'll need to load it like this on any HTML page:
new Worker('example.js', { type: 'module' });
In Firefox you'll get this error:
TypeError: O.hrtime.bigint is not a function utils.ts:103:26
In Chrome you'll get basically the same:
utils.ts:103 Uncaught (in promise) TypeError: O.hrtime.bigint is not a function
at z (utils.ts:103:27)
at kn (search.ts:110:27)
at wrap (w-orama.js:12:16)
Expected behavior
I expect the search to complete without the error.
In a Worker there is no window
object, but obviously a process
object, which doesn't behave like in Node.js.
You could be more specific about the bigint()
function by using this on line 102 of utils.ts:
if (typeof process !== 'undefined' && process.hrtime !== undefined && typeof process.hrtime.bigint === 'function') {
For the const isServer
I would use navigator
instead of window
because it's present in a Worker, but not Node.js.
Environment Info
OS: Linux
Browser: Firefox 121.0 & Chrome 120.0
Orama: 2.0.0-beta.12
Affected areas
Search, Environment/OS
Additional context
No response
Thanks for opening this! Fix is on the way #606
@tommy4st fixed. Will be likely released next week