appwrite / sdk-for-web

[READ-ONLY] Official Appwrite Web SDK ๐Ÿงก
https://appwrite.io
BSD 3-Clause "New" or "Revised" License
271 stars 58 forks source link

๐Ÿ› Bug Report: Not able to detect Appwrite Web SDK Types #54

Closed nimit2801 closed 1 year ago

nimit2801 commented 1 year ago

๐Ÿ‘Ÿ Reproduction steps

Step 1: Initialize a Vite Project

yarn create vite my-vue-app --template vanilla-ts

Root Cause Because "moduleResolution" is set to "bundler" in my tsconfig.json

Step 2: Install appwrite

yarn add appwrite

Step 3: Import App

import {Client} from "appwrite"

๐Ÿ‘ Expected behavior

It should not throw an error!

๐Ÿ‘Ž Actual Behavior

It throws an error

 Could not find a declaration file for module 'appwrite'. 'c:/Users/ASUS/OneDrive/Desktop/my-vue-app/node_modules/appwrite/dist/esm/sdk.js' implicitly has an 'any' type.
  There are types at 'c:/Users/ASUS/OneDrive/Desktop/my-vue-app/node_modules/appwrite/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'appwrite' library may need to update its package.json or typings.

image

๐ŸŽฒ Appwrite version

Version 0.10.x

๐Ÿ’ป Operating system

Linux

๐Ÿงฑ Your Environment

Nope!

๐Ÿ‘€ Have you spent some time to check if this issue has been raised before?

๐Ÿข Have you read the Code of Conduct?

stnguyen90 commented 1 year ago

@nimit2801 thanks for raising this issue!

After googling a bit it seems like this might be a newer typescript config and we can get it to work if we update a few things in the sdk.

Some additional reference:

nimit2801 commented 1 year ago

Possible solution which worked for me

My tsconfig.json file has "moduleResolution": "bundler" and if I set it to "moduleResolution": "node" it works for me!

stnguyen90 commented 1 year ago

We should be able to fix the problem If we update the exports in our package.json to:

  "exports": {
    ".": {
      "import": "./dist/esm/sdk.js",
      "require": "./dist/cjs/sdk.js",
      "types": "./types/index.d.ts"
    },
    "./package.json": "./package.json"
  },
nimit2801 commented 1 year ago

Thought for food https://github.com/gxmari007/vite-plugin-eslint/pull/60 this solves

nimit2801 commented 1 year ago

We should be able to fix the problem If we update the exports in our package.json to:

  "exports": {
    ".": {
      "import": "./dist/esm/sdk.js",
      "require": "./dist/cjs/sdk.js",
      "types": "./types/index.d.ts"
    },
    "./package.json": "./package.json"
  },

Yup, exactly. Can I make a PR?

subhojit-ghosh commented 1 year ago

Possible solution which worked for me

My tsconfig.json file has "moduleResolution": "bundler" and if I set it to "moduleResolution": "node" it works for me!

this is not working when I am trying to build the project. I am using Vitejs and react

image
nimit2801 commented 1 year ago

Possible solution which worked for me

My tsconfig.json file has "moduleResolution": "bundler" and if I set it to "moduleResolution": "node" it works for me!

this is not working when I am trying to build the project. I am using Vitejs and react image

Did you make the necessary changes? I suggested in the above solution.

Possible solution which worked for me

My tsconfig.json file has "moduleResolution": "bundler" and if I set it to "moduleResolution": "node" it works for me!

colbyfayock commented 10 months ago

still seeing this in a fresh vite react project - should this issue still be open?

image

is "moduleResolution": "node" the "right" solution? or a workaround? without knowing the total scope of that change, im wondering if it would be appropriate for all apps or if that might cause conflicts in some, but seems like it may be a package issue?

stnguyen90 commented 10 months ago

@colbyfayock

still seeing this in a fresh vite react project - should this issue still be open?

The fix will be in the next release of the SDK.

is "moduleResolution": "node" the "right" solution? or a workaround?

Both? The problem was the newer TS config is incompatible with our SDK.