# Node.js SDK - Square.Client is not a constructor

**URL:** <https://developer.squareup.com/forums/t/node-js-sdk-square-client-is-not-a-constructor/21202>\
**Category:** Questions\
**Created:** [February 26, 2025, 4:26am UTC](https://developer.squareup.com/forums/t/node-js-sdk-square-client-is-not-a-constructor/21202 "2025-02-26T04:26:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barman](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Barman](https://developer.squareup.com/forums/u/Barman)\
**Post date:** [February 26, 2025, 4:26am UTC](https://developer.squareup.com/forums/t/node-js-sdk-square-client-is-not-a-constructor/21202/1 "2025-02-26T04:26:55Z")

</div>

**Description:**

I am trying to use the Square Node.js SDK to build an application that receives webhooks from Square. I am following the documentation, but I am getting an error that says “Square.Client is not a constructor”.

I have tried the following:

- Installing the latest version of the Square Node.js SDK
- Importing the `Client` and `Environment` objects directly
- Accessing the `Client` and `Environment` objects directly from the `Square` module
- Creating a new, minimal Node.js project and installing only the `square` package
- Running a simple script that just initializes the `Square.Client`

However, I am still getting the same error.

Here is my code:

const Square = require(‘square’);

const client = new Square.Client({  
accessToken: ‘YOUR\_ACCESS\_TOKEN’,  
environment: Square.Environment.Sandbox,  
});

console.log(client);

I am using Node.js v22.14.0.

Can anyone help me with this?

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [February 26, 2025, 4:27am UTC](https://developer.squareup.com/forums/t/node-js-sdk-square-client-is-not-a-constructor/21202/2 "2025-02-26T04:27:10Z")

</div>

👋 I’m Square Dev AI, here to help answer your question!  
Based on the information you’ve provided, the following documentation will help answer your question:

> **[Square Node.js SDK Quickstart](https://developer.squareup.com/docs/sdks/nodejs/quick-start)**
>
> Learn how to quickly set up and test the Square Node.js SDK.

> **[Using the Square Node.js SDK](https://developer.squareup.com/docs/sdks/nodejs/using-nodejs-sdk)**
>
> Introduction to using the Square Node.js SDK features.

> **Additional Documentation**
>
> [Node.js SDK](https://developer.squareup.com/docs/sdks/nodejs)  
> [Set up SDK for a Node.js Project](https://developer.squareup.com/docs/sdks/nodejs/setup-project)  
> [Stay Current with the Node.js SDK&nbsp;Version](https://developer.squareup.com/docs/sdks/nodejs/stay-current-with-sdk-version)

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.  
Otherwise one of our Developer Advocates will provide additional assistance shortly.

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [February 26, 2025, 4:57pm UTC](https://developer.squareup.com/forums/t/node-js-sdk-square-client-is-not-a-constructor/21202/3 "2025-02-26T16:57:55Z")

</div>

The issue you’re encountering might be due to the way you’re importing the Square module. In the Square Node.js SDK, the `Client` and `Environment` objects are not directly accessible from the `Square` module. Instead, you should import them separately.

Here’s how you should structure your import statement and client initialization:

```javascript
const { Client, Environment } = require('square');

const client = new Client({
  accessToken: 'YOUR_ACCESS_TOKEN',
  environment: Environment.Sandbox,
});

console.log(client);

```

In this code, the `Client` and `Environment` objects are destructured from the `square` module. Then, a new `Client` instance is created using your access token and the `Environment.Sandbox` environment.

_This answer was reviewed by @Bryan-Square._

---

<div class="post-metadata">

**Author:** ![Barman](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Barman](https://developer.squareup.com/forums/u/Barman)\
**Post date:** [February 26, 2025, 9:18pm UTC](https://developer.squareup.com/forums/t/node-js-sdk-square-client-is-not-a-constructor/21202/4 "2025-02-26T21:18:15Z")

</div>

Thanks for the suggestion, but I’m still encountering the same error even when importing the `Client` and `Environment` objects separately.

Here’s the code I’m using:

const { Client, Environment } = require(‘square’);

console.log(Client); // Log the Client object  
console.log(Environment); // Log the Environment object

const client = new Client({  
accessToken: ‘YOUR\_ACCESS\_TOKEN’, // Replace with your actual access token  
environment: Environment.Sandbox,  
});

console.log(client);

And here’s the output I’m getting:

`undefined undefined TypeError: Cannot read properties of undefined (reading 'Sandbox')`

As you can see, both `Client` and `Environment` are undefined, and I’m still getting the “TypeError: Cannot read properties of undefined (reading ‘Sandbox’)” error.

I’ve tried this approach in both my original project and a clean project setup, but the error persists. I’m using Node.js v22.14.0.

Could there be another issue at play here? Any further guidance would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [February 26, 2025, 10:33pm UTC](https://developer.squareup.com/forums/t/node-js-sdk-square-client-is-not-a-constructor/21202/5 "2025-02-26T22:33:52Z")

</div>

What version of the SDK are you using? 🙂

---

<div class="post-metadata">

**Author:** ![Barman](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Barman](https://developer.squareup.com/forums/u/Barman)\
**Post date:** [February 26, 2025, 10:46pm UTC](https://developer.squareup.com/forums/t/node-js-sdk-square-client-is-not-a-constructor/21202/6 "2025-02-26T22:46:43Z")

</div>

I am using square@41.0.0

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [February 27, 2025, 12:10am UTC](https://developer.squareup.com/forums/t/node-js-sdk-square-client-is-not-a-constructor/21202/7 "2025-02-27T00:10:27Z")

</div>

If you try our [quickstart](https://developer.squareup.com/docs/sdks/nodejs/quick-start) example does it work:

```auto
const { SquareClient, SquareEnvironment, SquareError } = require("square");
require('dotenv').config()

const client = new SquareClient({
  token: process.env.SQUARE_ACCESS_TOKEN,
  environment: SquareEnvironment.Sandbox,
});

async function getLocations() {
  try {
    let listLocationsResponse = await client.locations.list();

    let locations = listLocationsResponse.locations;

    locations.forEach(function (location) {
      console.log(
        location.id + ": " +
        location.name + ", " +
        location.address.addressLine1 + ", " +
        location.address.locality
      );
    });
  } catch (error) {
    if (error instanceof SquareError) {
      error.errors.forEach(function (e) {
        console.log(e.category);
        console.log(e.code);
        console.log(e.detail);
      });
    } else {
      console.log("Unexpected error occurred: ", error);
    }
  }
};

getLocations();

```

🙂
