prisma / extension-read-replicas

Prisma Client Extension to add read replica support to your Prisma Client
Apache License 2.0
96 stars 6 forks source link

support esm #9

Closed trixobird closed 10 months ago

trixobird commented 10 months ago

It seems that is not working in esm mode. I managed to re-create it in https://github.com/prisma/read-replicas-demo with the following patch.

Subject: [PATCH] Error when esm


Index: package.json
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/package.json b/package.json
--- a/package.json  (revision 01fa72f67c06f615daddc8dbd4dcfa5ee9c7ce15)
+++ b/package.json  (revision 85cb7c2cd8d2837096a4c86453a13d13b33f100b)
@@ -1,8 +1,9 @@
 {
   "name": "script",
   "license": "MIT",
+  "type": "module",
   "scripts": {
-    "dev": "ts-node ./index.ts"
+    "dev": "ts-node --esm ./index.ts"
   },
   "dependencies": {
     "@prisma/client": "5.2.0",
Index: tsconfig.json
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tsconfig.json b/tsconfig.json
--- a/tsconfig.json (revision 01fa72f67c06f615daddc8dbd4dcfa5ee9c7ce15)
+++ b/tsconfig.json (revision 85cb7c2cd8d2837096a4c86453a13d13b33f100b)
@@ -2,6 +2,9 @@
   "compilerOptions": {
     "sourceMap": true,
     "outDir": "dist",
+    "module": "ES2022",
+    "moduleResolution": "node",
+    "target": "ES2022",
     "strict": true,
     "lib": ["esnext"],
     "esModuleInterop": true
SevInf commented 10 months ago

Hi @trixobird. The issue is fixed in 0.2.1 release of the extension. Could you update and check that fixed worked out for you?

trixobird commented 10 months ago

It did fix the issue, but now I am gettings type issues.

on import { readReplicas } from '@prisma/extension-read-replicas' and it does not go away even when I add a declaration file.

TS7016: Could not find a declaration file for module  @prisma/extension-read-replicas .
/Users/trixobird/w/testing/read-replicas-demo/node_modules/@prisma/extension-read-replicas/dist/index.js
implicitly has an  any  type.
Try
npm i --save-dev @types/prisma__extension-read-replicas
if it exists or add a new declaration (.d.ts) file containing
declare module '@prisma/extension-read-replicas'
SevInf commented 10 months ago

@trixobird Thank you! That problem should be fixed in 0.2.2