Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when generating with React Plugin #279

Closed
jonathangerbaud opened this issue Mar 20, 2023 · 2 comments
Closed

Error when generating with React Plugin #279

jonathangerbaud opened this issue Mar 20, 2023 · 2 comments

Comments

@jonathangerbaud
Copy link
Contributor

Hello, I got this error when I'm using the React lplugin:

npx zenstack generate
⌛️ ZenStack CLI v1.0.0-alpha.79, running plugins
⠋ Running plugin PrismaEnvironment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma

✔ Generated Prisma Client (4.11.0 | library) to .\node_modules\@prisma\client in 281ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

✔ Running plugin Prisma
✔ Running plugin Model Metadata
✔ Running plugin Access Policy
✖ Running plugin React

An unexpected error occurred:
 TypeError: Cannot read properties of undefined (reading 'updateOne')
    at generateModelHooks (D:\Coding\Web\DigitalNomading\node_modules\@zenstackhq\react\react-hooks-generator.js:232:87)
    at D:\Coding\Web\DigitalNomading\node_modules\@zenstackhq\react\react-hooks-generator.js:57:13
    at Array.forEach (<anonymous>)
    at D:\Coding\Web\DigitalNomading\node_modules\@zenstackhq\react\react-hooks-generator.js:55:16
    at Generator.next (<anonymous>)
    at D:\Coding\Web\DigitalNomading\node_modules\@zenstackhq\react\react-hooks-generator.js:31:71
    at new Promise (<anonymous>)
    at __awaiter (D:\Coding\Web\DigitalNomading\node_modules\@zenstackhq\react\react-hooks-generator.js:27:12)
    at generate (D:\Coding\Web\DigitalNomading\node_modules\@zenstackhq\react\react-hooks-generator.js:42:12)
    at D:\Coding\Web\DigitalNomading\node_modules\@zenstackhq\react\index.js:17:53

I just checked the code and I think you just need to add a "?" in https://github.com/zenstackhq/zenstack/blob/main/packages/plugins/react/src/react-hooks-generator.ts

Change
if (mapping?.update || (mapping as any).updateOne) {
To
if (mapping?.update || (mapping as any)?.updateOne) {

(Sorry, too lazy do to a PR...)

@ymc9 ymc9 mentioned this issue Mar 21, 2023
@ymc9
Copy link
Member

ymc9 commented Mar 21, 2023

Thanks again for filing this! I've made a fix to consistently deal with models marked @@ignore. Please update "zenstack" and "@zenstackhq/*" packages to "@latest" (version 1.0.0-alpha.81) and it should work now.

#283

@jonathangerbaud
Copy link
Contributor Author

Okay, it's working now with the last version. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants