Code Monkey home page Code Monkey logo

Comments (10)

lewebsimple avatar lewebsimple commented on May 20, 2024 1

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.

ymc9 avatar ymc9 commented on May 20, 2024 1

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.

NeoN0x avatar NeoN0x commented on May 20, 2024

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.

ymc9 avatar ymc9 commented on May 20, 2024

Thanks for reporting this! I'll look into it and share my finding soon.

from zenstack.

ymc9 avatar ymc9 commented on May 20, 2024

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.

ymc9 avatar ymc9 commented on May 20, 2024

Fixed in release 1.0.0-beta.7.

from zenstack.

NeoN0x avatar NeoN0x commented on May 20, 2024

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.

ymc9 avatar ymc9 commented on May 20, 2024

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.

NeoN0x avatar NeoN0x commented on May 20, 2024

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.

ymc9 avatar ymc9 commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.