zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

Cannot read properties of undefined (reading 'aggregate') #1406

Closed NatoBoram closed 5 months ago

NatoBoram commented 5 months ago

Description and expected behavior

When using the trpc plugin, there's table files generated at routers/<table_name>.ts. Let's take a table api_key_org.

export default function createRouter<Config extends BaseConfig>(
    router: RouterFactory<Config>,
    procedure: ProcBuilder<Config>,
) {
    return router({
        aggregate: procedure
            .input($Schema.Api_key_orgInputSchema.aggregate)
            .query(({ ctx, input }) =>
                checkRead(db(ctx).api_key_org.aggregate(input as any)),
            ),

This outputs an error:

TypeError: Cannot read properties of undefined (reading 'aggregate')

If we log $Schema, we get this:

[Module: null prototype] {
  default: {
    Api_key_orgInputSchema: {

So $Schema.Api_key_orgInputSchema.aggregate is actually at $Schema.default.Api_key_orgInputSchema.aggregate.

Screenshots

Environment (please complete the following information):

Additional context

ymc9 commented 5 months ago

Hi @NatoBoram , thanks for reporting this. Could you let me know what framework you're using? Do you use vite for bundling?

NatoBoram commented 5 months ago

I'm not using a framework, this is just an API from raw TypeScript files compiled with tsc. I'm just using Zenstack, tRPC, Express and Prisma.

ymc9 commented 5 months ago

I'm not using a framework, this is just an API from raw TypeScript files compiled with tsc. I'm just using Zenstack, tRPC, Express and Prisma.

Got it. I believe it has something to do with the interop between ESM and CJS modules. Do you have a sharable project? @NatoBoram

ymc9 commented 5 months ago

Fixed in 2.1.0