dynamodb-onetable icon indicating copy to clipboard operation
dynamodb-onetable copied to clipboard

Cannot resolve type when ESM

Open yamatatsu opened this issue 1 year ago • 3 comments

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):

  • OS: macOS 14.0
  • Node Version: v18.18.0
  • OneTable Version: 2.7.1
  • TypeScript Version: 5.2.2
  • Any other relevant environment information: nothing

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.

yamatatsu avatar Oct 09 '23 13:10 yamatatsu

Thank you for the reproduction repo.

mobsense avatar Oct 10 '23 01:10 mobsense

Any updates on this?

dbain-texada avatar Jan 24 '24 16:01 dbain-texada

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

Sorry for the delay.

Committed now.

mobsense avatar Feb 06 '24 02:02 mobsense