easypost-node icon indicating copy to clipboard operation
easypost-node copied to clipboard

[Bug]: TypeError: api_1.default is not a constructor in Nestjs

Open mustafakendiguzel opened this issue 1 year ago • 3 comments

Software Version

7.3.0

Language Version

21.4.0

Operating System

Windows

What happened?

  1. Imported easypost-node library in nestjs
  2. Attempt to create new EasyPostClient via
import EasyPost from '@easypost/api';
export class ShippingMailingService {
  private readonly easyPostClient: EasyPost
  constructor() { 
    this.easyPostClient = new EasyPost('apiKey')
  }
}
  1. Upon building, error is thrown that . TypeError: api_1.default is not a constructor
  2. Tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "removeComments": true,
    "noLib": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "target": "es2017",
    "sourceMap": true,
    "allowJs": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "lib": ["ES7", "ES2021", "DOM"],
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
  }
}

What was expected?

To be able to build the app while using EasyPostClient

Sample Code

import EasyPost from '@easypost/api';

export class ShippingMailingService {
  private readonly easyPostClient: EasyPost
  constructor() { 
    this.easyPostClient = new EasyPost('apiKey')
  }
}

Relevant logs

No response

mustafakendiguzel avatar Apr 15 '24 11:04 mustafakendiguzel

Hello there, thanks for writing in!

I believe there's an issue with your provided code snippet, you should be trying to construct an EasyPostClient object, not an EasyPost object

import EasyPostClient from '@easypost/api'; 

export class ShippingMailingService { 
  private readonly easyPostClient: EasyPostClient constructor() { this.easyPostClient = new EasyPostClient('apiKey') } }

nwithan8 avatar Apr 15 '24 14:04 nwithan8

Hello there, thanks for writing in!

I believe there's an issue with your provided code snippet, you should be trying to construct an EasyPostClient object, not an EasyPost object

import EasyPostClient from '@easypost/api'; 

export class ShippingMailingService { 
  private readonly easyPostClient: EasyPostClient constructor() { this.easyPostClient = new EasyPostClient('apiKey') } }

Thanks for the answer @nwithan8. I get the same error that didn't solve this problem.

mustafakendiguzel avatar Apr 15 '24 16:04 mustafakendiguzel

has anyone found a workaround for this yet?

heindrik avatar Aug 14 '24 22:08 heindrik