From f4f35cdb4fa49615ee54db95f522c36ff0e38711 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 24 Jul 2023 18:48:14 +0300 Subject: [PATCH] docs: add troubleshooting for js client (#4597) Add troubleshooting on possible Typescript error that can occur when importing the JS Client --- docs/content/js-client/overview.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/docs/content/js-client/overview.md b/docs/content/js-client/overview.md index fd550b6ae6..ce5e2a770d 100644 --- a/docs/content/js-client/overview.md +++ b/docs/content/js-client/overview.md @@ -22,12 +22,32 @@ npm install @medusajs/medusa-js Import Medusa as a default import and initiate it: -```js +```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa() ``` +### Troubleshooting: Could not find a declaration file for module '@medusajs/medusa-js' + +If you import `@medusajs/medusa-js` in your code and see the following TypeScript error: + +```bash +Could not find a declaration file for module '@medusajs/medusa-js' +``` + +Make sure to set `moduleResolution` in your `tsconfig.json` to `nodenext` or `node`: + +```json title=tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "nodenext", + // ... + }, + // ... +} +``` + --- ## How to Use this Reference @@ -36,7 +56,7 @@ You'll find in the sidebar of this reference names of different resources. These For example, to create a new customer you can access the [create](/references/js-client/classes/CustomerResource#create) method under the [customers](/references/js-client/classes/CustomerResource) property of your client: -```js +```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa() @@ -49,7 +69,7 @@ medusa.customers.create({ The `customers` resource also has another resource `addresses` nested inside it with its own method that you can access similarly: -```js +```ts medusa.customers.addresses.addAddress({ // data }) @@ -79,7 +99,7 @@ Authentication using cookies is done automatically by Axios, which is used withi The package can be initialized with several options: -```js +```ts const medusa = new Medusa({ maxRetries: 3, baseUrl: "https://api.example.com", @@ -91,4 +111,4 @@ const medusa = new Medusa({ | `maxRetries` | `0` | The amount of times a request is retried. | | `baseUrl` | `'http://localhost:9000'` | The url to which requests are made to. | | `apiKey` | `''` | Optional API key used for authenticating admin requests. | -| `publishableApiKey` | `''` | Optional publishable API key used for storefront requests. You can create a publishable API key either using the [admin APIs](../development/publishable-api-keys/admin/manage-publishable-api-keys.mdx) or the [Medusa admin](../user-guide/settings/publishable-api-keys.mdx). | \ No newline at end of file +| `publishableApiKey` | `''` | Optional publishable API key used for storefront requests. You can create a publishable API key either using the [admin APIs](../development/publishable-api-keys/admin/manage-publishable-api-keys.mdx) or the [Medusa admin](../user-guide/settings/publishable-api-keys.mdx). |