shiftcode/dynamo-easy

Consider changing "DynamoDB" to a default import

refactorthis opened this issue · 1 comments

Hi,

I've just been trying to use your library as it supports transactions (thanks!!) but I can't seem to get it to work due to the below error. Let me know if there is something I am doing wrong.

Describe the bug

Constructing "DynamoDB" will crash at run-time because it's an import namespace object, not a constructor [call-import-namespace]

node_modules/@shiftcoders/dynamo-easy/dist/_esm5/dynamo/dynamo-db-wrapper.js:14:40:
  14 │         this.dynamoDB = dynamoDB || new DynamoDB();
     ╵                                         ~~~~~~~~

Consider changing "DynamoDB" to a default import instead:

node_modules/@shiftcoders/dynamo-easy/dist/_esm5/dynamo/dynamo-db-wrapper.js:4:7:
  4 │ import * as DynamoDB from 'aws-sdk/clients/dynamodb';
    │        ~~~~~~~~~~~~~
    ╵        DynamoDB

This then fails at runtime as expected as it's attempting to construct a namespace.

To Reproduce
Using the recommended aws-sdk version and a fresh install, I get this error.

Expected behavior
Default import should be used.

Workaround
I can work around the runtime issue by providing the DynamoDB object to the store as below

import { DynamoDB } from "aws-sdk";
new DynamoStore(new DynamoDB());

Hi @refactorthis. Thanks for reaching out. When reading your description the ts compiler option esModuleInterop (doc) comes to my mind. Is it enabled in your project? Hope this helps, reach out if the problem persist, in the best case with a sample repo I can check out and reproduce the issue.