sensedeep / dynamodb-onetable

DynamoDB access and management for one table designs with NodeJS
https://doc.onetable.io/
MIT License
690 stars 109 forks source link

Cannot resolve type when ESM #506

Closed yamatatsu closed 7 months ago

yamatatsu commented 1 year ago

Describe the bug

When using Native ESM following TypeScript Official Blog, Onetable cannot resolve type(e.g. Table, OneSchema and Entity).

When cjs:

image

When esm:

image

To Reproduce

https://github.com/yamatatsu/reproduction-onetable-unresolve-type

Steps to reproduce the behavior:

  1. Clone this repository.
  2. npm i.
  3. Open ./debug.ts and you can see no error on schema.foo.bar.
  4. And it will be error when remove "type": "module", from package.json.

Environment (please complete the following information):

Additional context

I found some solutions:

  1. Add .js to all imports in *.d.ts following Official Documentation.
  2. I don't know why but it resolve this issue to replace dist/mjs/index.d.ts to dist/cjs/index.d.ts at package.json#L7 and remove exports: from package.json.
    It probably also resolve to separate directories to mjs and types same as any other libraries such as @aws-sdk/client-dynamodb.
mobsense commented 1 year ago

Thank you for the reproduction repo.

dbain-texada commented 10 months ago

Any updates on this?

mobsense commented 9 months ago

I like your solution (1). Seems to work.

Sorry for the delay.

Committed now.