Typescript cannot find module 'lunr'

I have a file src/client/main.tswith this code:

import * as lunr from 'lunr';

console.log('main');

I set dt captions for lunr typings install dt~lunr --save --globals

My tsconfig.json file has the following selectors:

"filesGlob": [
  "src/**/*.ts"
],
"files": [
  "typings/index.d.ts"
]

Why doesn't the typescript compiler find a module lunr? The compiler always outputserror TS2307: Cannot find module 'lunr'

+4
source share
1 answer

Looking at the typing for lunr, I saw what it defined namespace. https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html

This means that it should not be used as an import, but as a namespace of a global object. So my main.ts file becomes:

lunr(function() { console.log('do something with lunr') });

console.log('main');

lunr html script script.

2 ... ...

0

All Articles