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!
https://docs.orama.com
Other
8.53k stars 285 forks source link

tsconfig with module option set to Node16 orama refuses to import #703

Open gabrielsantosblanchet opened 5 months ago

gabrielsantosblanchet commented 5 months ago

Describe the bug

when using tsconfig option "module": "Node16", "moduleResolution": "Node16" in a commonJS project orama refuses to import correctly

I'm using these option as per the documentation set in https://www.typescriptlang.org/docs/handbook/modules/reference.html#the-module-compiler-option

To Reproduce

the code will not work, as in it doesn't event compile

Expected behavior

since orama emits cjs file it should just be able to import the correct one

Environment Info

windows: 11
typescript: 5.4.3
node: v18.20.2
orama: 1.2.11

Affected areas

Environment/OS

Additional context

if needed I can provide more details when asked

shubh2336 commented 5 months ago

Faced the same issue, got it working by dynamic import (as a workaround).

const searchFunction = async (data) => {
  return import("@orama/orama").then(async (module) => {
    const searchDB = await module.create({
      schema: { ... }
    });

    // Implement search logic below
  })
};
micheleriva commented 2 weeks ago

@matijagaspar, @allevo, can we do something to make this less painful?