shiftcode / dynamo-easy

DynamoDB client for NodeJS and browser with a fluent api to build requests. We take care of the type mapping between JS and DynamoDB, customizable trough typescript decorators.
https://shiftcode.github.io/dynamo-easy/
MIT License
206 stars 27 forks source link

Consider changing "DynamoDB" to a default import #395

Closed refactorthis closed 1 year ago

refactorthis commented 2 years ago

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());
michaelwittwer commented 2 years ago

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.