easypost-node
easypost-node copied to clipboard
[Bug]: TypeError: api_1.default is not a constructor in Nestjs
Software Version
7.3.0
Language Version
21.4.0
Operating System
Windows
What happened?
- Imported easypost-node library in nestjs
- Attempt to create new EasyPostClient via
import EasyPost from '@easypost/api';
export class ShippingMailingService {
private readonly easyPostClient: EasyPost
constructor() {
this.easyPostClient = new EasyPost('apiKey')
}
}
- Upon building, error is thrown that . TypeError: api_1.default is not a constructor
- 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
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') } }
Hello there, thanks for writing in!
I believe there's an issue with your provided code snippet, you should be trying to construct an
EasyPostClientobject, not anEasyPostobjectimport 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.
has anyone found a workaround for this yet?