edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

CJS needs explicit named exports, eg not `export *` in `reflection.ts`

Open jackfischer opened this issue 3 months ago • 4 comments

Describe the bug Very unclear when/how this problem emerged for us in our nextjs application but we're noticing the following error. Queries still succeed!

Reproduction Running any querybuilder based query

 ⚠ [externals]/gel/dist/reflection/index.js
unexpected export *
export * used with module [externals]/gel/dist/reflection/index.js [external] (gel/dist/reflection/index.js, cjs) which is a CommonJS module with exports only available at runtime
List all export names manually (`export { a, b, c } from "...") or rewrite the module to ESM, to avoid the additional runtime code.`

Import trace:
  [externals]/gel/dist/reflection/index.js [external]
  ./dbschema/edgeql-js/index.ts [Route]
  ./utils/auth/authProviderHelpers.ts [Route]
  ./utils/ActivitiesData/sources/gitlab.ts [Route]
  ./pages/api/auth/[...nextauth].ts [Route]

Versions (please complete the following information):

  • OS:
  • EdgeDB version (e.g. 2.0): 6.10
  • EdgeDB CLI version (e.g. 2.0): 7.7.0
  • edgedb-js version (e.g. 0.20.10;): Generate 0.6.4, gel 2.1.1
  • Node/Deno version: v22.15.0.

jackfischer avatar Sep 01 '25 13:09 jackfischer

+1 to this, it's preventing client side usage of edgeql for server side functions in SolidStart apps.

nileshp87 avatar Sep 01 '25 23:09 nileshp87

Looks like this just needs explicit exports in reflection.ts

--- a/dbschema/edgeql-js/reflection.ts
+++ b/dbschema/edgeql-js/reflection.ts
@@ -1,6 +1,26 @@
 // GENERATED by @gel/generate v0.6.4

-export * from "gel/dist/reflection/index";
+export {
+  introspect,
+  Capabilities,
+  Cardinality,
+  TypeKind,
+  ExpressionKind,
+  SelectModifierKind,
+  OperatorKind,
+  util,
+  StrictMap,
+  StrictMapSet,
+  reservedKeywords,
+  generateTSTypeFromCodec,
+  defineCodecGeneratorTuple,
+  defaultCodecGenerators,
+  generateTsObject,
+  generateTsObjectField,
+  defaultApplyCardinalityToTsType,
+  ImportMap,
+  analyzeQuery,
+} from "gel/dist/reflection/index";

jackfischer avatar Oct 10 '25 21:10 jackfischer

@jackfischer

Can you share the module and moduleResolution values you use in your tsconfig.json, and which version of TypeScript? We need to do a big remodel of our emitted code in light of the current bundler vs. node16 vs. esm style module setup, so just want to understand which setup gives this side-effect.

scotttrinh avatar Oct 10 '25 21:10 scotttrinh

Of course,

    "module": "ESNext",
    "moduleResolution": "Bundler",

Typescript 5.9.2

jackfischer avatar Oct 15 '25 00:10 jackfischer