meilisearch / meilisearch-js

JavaScript client for the Meilisearch API

Home Page:https://www.meilisearch.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dependencies or missing imports not found when using Typescript

Gideon-Felt opened this issue · comments

Description
After adding meilisearch to my nest.js project I can no longer run/build the application, as typescript is now throwing errors.

Expected behavior
The library could be loaded properly

Current behavior
Crash when building.
I am however able to use the library when I use Jupyter Notebook with the ijavascript kernal installed, I was able to create an index, addDocuments, and search them.

Screenshots or Logs


5 async function httpResponseErrorHandler(response: Response): Promise<Response> {                                                               
                                                    ~~~~~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/errors/http-error-handler.ts:5:70 - error TS2304: Cannot find name 'Response'.

5 async function httpResponseErrorHandler(response: Response): Promise<Response> {
                                                                       ~~~~~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/errors/meilisearch-communication-error.ts:11:11 - error TS2304: Cannot find name 'Response'.

11     body: Response | FetchError,
             ~~~~~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/errors/meilisearch-communication-error.ts:22:25 - error TS2304: Cannot find name 'Response'.

22     if (body instanceof Response) {
                           ~~~~~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/errors/meilisearch-communication-error.ts:27:25 - error TS2339: Property 'errno' does not exist on type 'Error'.

27       this.errno = body.errno
                           ~~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/errors/meilisearch-communication-error.ts:28:24 - error TS2339: Property 'code' does not exist on type 'Error'.

28       this.code = body.code
                          ~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/http-requests.ts:41:40 - error TS2304: Cannot find name 'HeadersInit'.

41 function cloneAndParseHeaders(headers: HeadersInit): Record<string, string> {
                                          ~~~~~~~~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/http-requests.ts:49:18 - error TS2304: Cannot find name 'Headers'.

49     ;(headers as Headers).forEach((value, key) => (clonedHeaders[key] = value))
                    ~~~~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/http-requests.ts:121:16 - error TS2304: Cannot find name 'fetch'.

121     if (typeof fetch === 'undefined') {
                   ~~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/http-requests.ts:143:59 - error TS2552: Cannot find name 'fetch'. Did you mean 'fetchFn'?

143       const fetchFn = this.httpClient ? this.httpClient : fetch
                                                              ~~~~~

  node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/http-requests.ts:143:13
    143       const fetchFn = this.httpClient ? this.httpClient : fetch
                    ~~~~~~~
    'fetchFn' is declared here.
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/types/types.ts:13:32 - error TS2304: Cannot find name 'RequestInit'.

13   requestConfig?: Partial<Omit<RequestInit, 'body' | 'method'>>
                                  ~~~~~~~~~~~
node_modules/.pnpm/meilisearch@0.35.0/node_modules/meilisearch/src/types/types.ts:14:39 - error TS2304: Cannot find name 'RequestInit'.

14   httpClient?: (input: string, init?: RequestInit) => Promise<any>
                                         ~~~~~~~~~~~

Found 12 error(s).

Environment (please complete the following information):

  • OS: Windows (meilisearch service running on WSL/Docker).
  • Meilisearch version: v1.4.2
  • meilisearch-js version: v0.35.0
  • node.js version: v18.13.0
  • Browser: I'm using node at the moment, I've not begun implementing a front-end for my project.

I was able to fix this by modifying my tsconfig.json as follows, but it should be documented somewhere.

"compilerOptions": {
        "lib": ["DOM"]
}

Hi @Gideon-Felt

Where do you think we could document this information? I thought it was very use-case-specific... But I'm willing to accept a PR if you want to contribute!

Thanks for using Meilisearch!