bhushankummar / amazon-mws

Amazon MWS NodeJS Wrapper
MIT License
197 stars 78 forks source link

Error: amazon_mws_1.default is not a constructor when using TypeScript and Nest.js #143

Closed erezhod closed 4 years ago

erezhod commented 4 years ago

Hello :)

I have a server app written using the Nest.js framework with TypeScript.

When creating an instance of the MwsApi like the docs state, I am getting the following error in runtime: [Nest] 63902 - 09/07/2020, 8:46:42 PM [ExceptionHandler] amazon_mws_1.default is not a constructor +62ms

This is my code:

import { Injectable } from '@nestjs/common';
import MwsApi from 'amazon-mws';

@Injectable()
export class MwsService {
    private api: MwsApi;

    constructor() {
        this.api = new MwsApi();
        this.api.setApiKey('xxx', 'xxx');
    }
}

And this is the JS compiled/transpiled code:

const common_1 = require("@nestjs/common");
const amazon_mws_1 = require("amazon-mws");
let MwsService = class MwsService {
    constructor() {
        this.api = new amazon_mws_1.default();
        this.api.setApiKey('xxx', 'xxx');
    }
}

What could be the issue?

Thanks!

erezhod commented 4 years ago

I have solved the issue. The magic is changing the important statement to: import * as MwsApi from 'amazon-mws';