askorama / orama

🌌 Fast, dependency-free, full-text and vector search engine with typo tolerance, filters, facets, stemming, and more. Works with any JavaScript runtime, browser, server, service!

Home Page:https://docs.askorama.ai

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: process.release is undefined when db is a proxy

jblyberg opened this issue · comments

Describe the bug

I'm storing the db in a vuejs pinia store and when I'm getting the following error:

TypeError: process.release is undefined
    isInsideNode utils.ts:91
    getNanosecondsTime utils.ts:119
    fullTextSearch search-fulltext.ts:26
    search2 search.ts:108
    searchWithHighlight index.ts:98

Reference:

export function isInsideNode(): boolean {
  return typeof process !== 'undefined' && process.release.name === 'node'
}

This seems to be as issue with how Orama interacts with vue's reactivity. Started when I upgraded to 2.0.0.

To Reproduce

Fine:

const db = await create({
  schema: {
    text: 'string'
  }
})

// Insert a document
await insert(db, { text: 'hello world' })

// Use the plugin's searchWithHighlight function to query the database
const results = await searchWithHighlight(db, { term: 'hello' })

Assign db as a store value and use it in a component and it fails:

const store = useStore();
const results = await searchWithHighlight(store.db, { term: 'hello' })

Expected behavior

It should detect the web platform correctly and not error.

Environment Info

Orama 2.0.0

Affected areas

Search

Additional context

No response

Folow-up. I am wondering if this has something to do with vite trying to polyfill nodejs. Maybe adding a simple check:

export function isInsideNode(): boolean {
  return typeof process !== 'undefined' && process.release && process.release.name === 'node' 
}

Just released your fix at #611. Thanks!