Search code examples
javascripttypescripttypescript-typingslunrjs

Importing lunr in typescript?


The Defintely Typed repository imports it like this:

import * as lunr from 'lunr';

However when using it like that in Stackblitz it errors with:

lunr is not a function

Thoughts? This is the Stackblitz:

https://stackblitz.com/edit/typescript-lunr-test


Solution

  • Definitely Typed is using an older version of lunr, so I tried a different import: import lunr from "lunr", which throws an error saying posting[field] is undefined (source code).

    I then noticed that the "text" field being used in the Builder was not initialized in the index. Adding this.field("text") in the index resulted in the page loading without errors.