docs: add troubleshooting for js client (#4597)
Add troubleshooting on possible Typescript error that can occur when importing the JS Client
This commit is contained in:
@@ -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). |
|
||||
| `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). |
|
||||
|
||||
Reference in New Issue
Block a user