fly-apps / litefs-js

JavaScript utilities for working with LiteFS on Fly.io
https://fly.io/blog/introducing-litefs
MIT License
160 stars 4 forks source link

Add support for Native ESM #5

Open onemen opened 1 year ago

onemen commented 1 year ago

importing 'litefs-js/remix' in ESM project ("type": "module" in package.json ) is not working

 error TS2307: Cannot find module 'litefs-js/remix' or its corresponding type declarations.

10 import { ensureInstance } from 'litefs-js/remix'
                                  ~~~~~~~~~~~~~~~~~

add this to package.json to fix this issue

    "name": "litefs-js",
    "version": "1.1.2",
    "description": "JavaScript utilities for working with LiteFS on Fly.io",
    "types": "dist/index.d.ts",
    "main": "dist/index.js",
+   "exports": {
+    ".": {
+       "types": "./dist/index.d.ts",
+       "default": "./dist/index.js"
+     },
+     "./remix": {
+       "types": "./dist/remix.d.ts",
+       "default": "./dist/remix.js"
+     }
+   },
    "scripts": {

although the above patch fixed this issue, maybe it is better to add build script to build both dist/esm and dist/cjs each with its own .d.ts files.

kentcdodds commented 1 year ago

I just noticed this! Sorry about that. I think I would like these changes, but I don't have time to make them myself.