js-sdk: Can't get type declarations to work in ES Module project

I’ve read a bunch of other issues which gave me the impression that with the "type": "module" setup, it should work out of the box, but I’m clearly doing something else wrong.

The warning on the import statement is:

Could not find a declaration file for module 'pocketbase'. 's:/New folder (5)/pocketbase/node_modules/pocketbase/dist/pocketbase.es.mjs' implicitly has an 'any' type.

2022-11-30T22-21-54 Thanks in advance for any help with this.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I still have this issue. Tried to use latest TypeScript 5+ and 4.9.4

image

My tsconfig.json:

{
  "@schema": "https://json.schemastore.org/tsconfig.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
  "compilerOptions": {
    "baseUrl": ".",
    "moduleResolution": "node",
    "strict": true,
    "paths": {
      "@/*": ["./src/*"]
    },
    "types": ["naive-ui/volar"]
  }
}

PS: Pocketbase js-sdk verison 0.15.2

Encountered this issue with pocketbase v.0.9.1.

Resolved by updating TS to v4.9.4, as mentioned by @ganigeorgiev.

The “fix” should be available with the v0.8.3 release.

I think I found the related TS issue - https://github.com/microsoft/TypeScript/issues/50762.

It seems that the problem is with how the exports is resolved and ts for some reason makes a guess where the declaration file is located instead of loading it directly from the types prop (either in the root level or as part of an exports block; the position of the types key also seems to matter).

I’ll reopen the issue and will update sometime later the file extension to generate it with .mts.

Thank you so much!

I don’t know what’s wrong with my setup. Maybe you can reproduce it with Docker?

FROM node:alpine

WORKDIR /test

RUN echo $'{\n\
  "type": "module"\n\
}' > package.json;

RUN npm install typescript pocketbase

RUN echo $'{\n\
  "compilerOptions": {\n\
    "module": "ESNext",\n\
    "moduleResolution": "NodeNext",\n\
    "target": "ESNext",\n\
    "strict": true,\n\
  },\n\
  "include": ["*.ts"]\n\
}' > tsconfig.json;

RUN echo $'\n\
import PocketBase from "pocketbase";\n\
const pocketbase = new PocketBase("http://localhost:8090");\n\
'> app.ts;

RUN npx tsc

It is also possible that TS is looking for .mts ending definition file since the exported has .mjs extension, or in other words you can test renaming the definition file to .mts.