Comments (10)
The fix in 1.0.0-beta.7 works flawlessly in the same Nuxt projet that previously didn't work.
Thanks π
update well ... it installs correctly but the generated tRPC routers can't import named exports from @zenstackhq/runtime/zod/input
because they are CJS. It seems the following might work:
import zodInput from '@zenstackhq/runtime/zod/input';
const { UserInputSchema, PostInputSchema } = zodInput;
instead of import { UserInputSchema, PostInputSchema } from '@zenstackhq/runtime/zod/input';
from zenstack.
Hi @NeoN0x , I've added type annotation to the generated Zod schemas and pushed a new "beta.8" release. Could you check if it's working in your project now? Thanks!
from zenstack.
Hello,
Same issue with a simpler project, and pnpm, but without Nuxt/any dependency, neither tsconfig.json, when trying zenstack generate
, after zenstack init
β Running plugin ZodError compiling generated code:
../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/.zenstack/zod/input/PostInput.schema.ts:22:26 - error TS2742: The inferred type of 'PostInputSchema' cannot be named without a reference to '.pnpm/@[email protected][email protected]/node_modules/.prisma/client'. This is likely not portable. A type annotation is necessary.
22 export const PostInputSchema = {
~~~~~~~~~~~~~~~
../node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/.zenstack/zod/input/PostInput.schema.ts:22:26 - error TS2742: The inferred type of 'PostInputSchema' cannot be named without a reference to '.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime'. This is likely not portable. A type annotation is necessary.
(... more error like that)
from zenstack.
Thanks for reporting this! I'll look into it and share my finding soon.
from zenstack.
Hi @lewebsimple @NeoN0x , it turns out that tsc
is confused by the symlink structure generated by pnpm due to ZenStack's peer dependency on "@prisma/client". I think it's safe to just remove that peer dependency, and the problem should just go away.
I'll make a fix in the upcoming release.
from zenstack.
Fixed in release 1.0.0-beta.7.
from zenstack.
Thanks a lot for your prompt answer & fix.
I'm experimenting with pnpm/pnpm workspace, and just installed zenstack "zenstack": "1.0.0-beta.7" and prisma with pnpm, and having the sample default model (schema.zmodel with User and Post).
However, I'm still having the issue :
$ pnpm zenstack generate
βοΈ ZenStack CLI v1.0.0-beta.7, running plugins
β Running plugin Prisma
β Running plugin Model Metadata
β Running plugin Access Policy
β Running plugin ZodError compiling generated code:
../node_modules/.pnpm/@[email protected]/node_modules/.zenstack/zod/input/PostInput.schema.ts:22:26 - error TS2742: The inferred type of 'PostInputSchema' cannot be named without a reference to '.pnpm/@[email protected][email protected]/node_modules/.prisma/client'. This is likely not portable. A type annotation is necessary.
22 export const PostInputSchema = {
~~~~~~~~~~~~~~~
../node_modules/.pnpm/@[email protected]/node_modules/.zenstack/zod/input/PostInput.schema.ts:22:26 - error TS2742: The inferred type of 'PostInputSchema' cannot be named without a reference to '.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime'. This is likely not portable. A type annotation is necessary.
22 export const PostInputSchema = {
~~~~~~~~~~~~~~~
(lot of error like that)
But it seems that this is specifically linked to workspace.
By not using workspace, it does not have the error.
My pnpm-workspace.yaml
packages:
- 'db/**'
- 'back/**'
- 'front/**'
# exclude packages that are inside test directories
- '!**/src/test/**'
I'm very new to monorepo things, and after googling it (https://typescript.tv/errors/includes/ts2xxx/ts2742) it is something that might be related (quoted: In a monorepository the error TS2742 can show up when you are using a package that has not set a βmainβ property in its βpackage.jsonβ file. Sometimes it also happens that there is a βtypesβ property which does not point to the correct typings. Make sure both paths are present and relative:)
If this is not fixable, what do you advise, should Switch back to npm/yarn workspaces ?
from zenstack.
Hey @NeoN0x , thanks for confirming this! I just tried pnpm workspace and do see the same problems. I thought explicit type annotation could be avoided, but it seems tsc
just can't figure out the correct resolutions in some cases. Pnpm is cool but it's symbolic link mechanism has many edge cases :(.
Let me add those annotations and I think the problems should just go away. Will publish a new version soon.
from zenstack.
Hi @ymc9 ,
I set up the beta.7 to have the exact issue, then only changed to beta.8 and worked perfectly !
Thanks a lot for your dedication ;)
--
For what it worth, further my previous exploration, I managed to use pnpm workspace + beta.7 with the following setting in the schema.zmodel
plugin zod {
provider = '@core/zod'
output = 'zod'
}
So I think somehow the issue with using the node_module and conflicted somewhere in the symlink and specifying the output make it clear.
I understand that edge case are very complexe to manage for library like zenstack. I'm also impressed by the by the fix 574 and how it makes this more robust.
from zenstack.
Awesome! So happy it's working now.
Yes, you're right. If the zod plugin's output location is hoisted outside "node_modules" the problem doesn't happen. Having the default configuration to work flawlessly will probably reduce some friction.
Thanks for catching this issue. Feel free to join discord if you haven't π: https://go.zenstack.dev/chat
from zenstack.
Related Issues (20)
- Model inheritance doesn't check for cycles
- LSP VSCode: Linter doesn't complain when using `previewFeatures = ["multiSchema"]` but not including `@@schema` on models / enums
- Polymorphic extends using `enum` for the type when using @@delegate HOT 5
- Update permission buggy when used in @@deny HOT 1
- [ZModel] Insufficient type checking for "in" operator
- Two one-to-many relations on the same model generated wrong model meta data
- Issue using @@index with @@delegate HOT 2
- false error on @relation in vscode extension when using multiple schemas HOT 5
- auth() with import causes linking-error HOT 2
- [Feature Request] Provide Migrations API HOT 1
- [Zod] Field with `auth()` in `@default()` should be generated as optional in zod schemas HOT 1
- Allow accessing all fields through auth() when @@auth is applied on model with @@delegate HOT 3
- Typecasting "Bytes" Fields HOT 2
- [Feature Request] Honojs server adapter support
- Zenstack having problems with upserting relations with compound keys HOT 2
- [Feature Request] Compatibility with Prisma "omit" feature
- Prisma --no-engine CLI option is not available until 5.2.0
- Zod schemas should use `.optional()` instead of `.nullish()` to represent optional fields
- [Feature Request] Disable hooks that generates files outside of node_modules in CLI HOT 1
- Policy compilation errors with deep nested post-update rules
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zenstack.