goshippo / shippo-javascript-sdk

MIT License
5 stars 0 forks source link

Headers is not defined error in NestJS application using Shippo Node.js SDK #45

Closed radivojenovamedia closed 1 month ago

radivojenovamedia commented 1 month ago

Describe the bug: I'm encountering a Headers is not defined error when making any request using the Shippo Node.js SDK in a NestJS application.

To Reproduce: Steps to reproduce the behavior:

1. Install the Shippo Node.js SDK.
2. Set up a NestJS controller and attempt to create a shipment using the SDK.

Expected behavior: The request should successfully create a shipment without errors.

Screenshot: image

`import { Controller, Post } from '@nestjs/common'; import { DistanceUnitEnum, Shippo, WeightUnitEnum } from 'shippo';

@Controller('shippo') export class ShippoController { shippo: Shippo; constructor() { this.shippo = new Shippo({ apiKeyHeader: 'shippo_test_shippo_token', shippoApiVersion: '2018-02-08', }); }

@Post('create') async createShipment() { const shipment = this.shippo.shipments.create({ addressFrom: { zip: '22191', country: 'Virginia', }, addressTo: { zip: '27359', country: 'North Carolina', }, parcels: [ { massUnit: WeightUnitEnum.Kg, weight: '3.3', width: '100', height: '100', length: '10', distanceUnit: DistanceUnitEnum.Cm, }, ], });

return shipment.catch((error) => {
  console.log(error);
});

} }`

shippo-lueders commented 1 month ago

hmm, the fetch api should be available in the supported node versions (v18 and v20), can you confirm which version of node you're using?

radivojenovamedia commented 1 month ago

I am using Node.js version 18.18.0. I tested the SDK without NestJS, and it worked correctly. However, when integrating it with the NestJS framework, the headers are not being recognized, despite the declaration for the Headers class existing in the lib.d.ts file.

radivojenovamedia commented 1 month ago

@shippo-lueders I believe I have found the cause of the issue. It seems that the nestjs-fetch library was the problem. Once I removed it, the SDK started working correctly. My apologies for any inconvenience this may have caused.

shippo-lueders commented 1 month ago

ah, good to know. glad things are working for you now and thanks for letting us know the root cause!