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 89 forks source link

Cannot find module './zod' or its corresponding type declarations. #1667

Closed Tsimopak closed 1 month ago

Tsimopak commented 1 month ago

An error in line 6 of the generated enhance.ts

This happens when I provide the enhancer plugin in schema.zmodel like so, image

This happens when I provide the enhancer plugin in schema.zmodel like so, image

Why do I provide it again with the default settings? Because apparently, Zenstack does not generate the enhance API in node_modules/.zenstack if I don't However, if I do provide the plugin, the CLI complains about the aforementioned error when I do zenstack generate image

Reference from discord: https://discord.com/channels/1035538056146595961/1274540789946388551/1274540789946388551

jiashengguo commented 1 month ago

@ymc9 should we change the generated import path for zod?

import * as zodSchemas from '@zenstackhq/runtime/zod'
ymc9 commented 1 month ago

@ymc9 should we change the generated import path for zod?

import * as zodSchemas from '@zenstackhq/runtime/zod'

I roughly remember we couldn't do that due to cyclic references. Let me check why it's broken.

zysam commented 1 month ago

@ymc9 could you release version like beta or others on npm? so I can run the script.

spacesick commented 1 month ago

Here is my workaround in the meantime: Add the following to schema.zmodel, image and import what you need from "./generated_zenstack/<module name>"

ymc9 commented 1 month ago

Fixed in 2.5.0