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

Generated "enhance" function not found. Please run zenstack generate first. #1983

Open
Izag-Larm opened this issue Feb 8, 2025 · 12 comments

Comments

@Izag-Larm
Copy link

Izag-Larm commented Feb 8, 2025

Description and expected behavior
I started the development of a Nuxt application and after defining my zenstack schema, I wrote an API route for the server to retrieve a file entity from the database. But I get an error after having at the execution level of enhance(prisma). However I have already run npx zenstack generate and npx prisma db push.

Screenshots
zmodel

Image

Image

global prisma client

Image

route api

Image

Environment (please complete the following information):

  • ZenStack version: 2.11.5
  • Prisma version: 6.3.x
  • Database type: Postgresql

Additional context
I running nuxt with compatibility version 4

@ymc9
Copy link
Member

ymc9 commented Feb 23, 2025

Hi @Izag-Larm , just to confirm, do you have any regex validation patterns in the ZModel? We recently discovered an issue that invalid regex patterns can cause the "enhance function not found" error.

@sanny-io
Copy link

@ymc9 I am also having this issue. I'm using regex in the zmodel, but the regex appears fine to me, and the same error happens when I remove the regex.

color       String               @default('#787878') @regex('^#(?:[0-9a-fA-F]{3}){1,2}$')

Interestingly, the error only happens when I run my app with tsx. If I build it and run it with node, it works fine. Additionally, the error does not appear in my Next.js app at all - it only appears in my express app.

I know you can't do much without a repro, so I'll see if I can set one up and open another issue if need be.

@Izag-Larm
Copy link
Author

Hi @Izag-Larm , just to confirm, do you have any regex validation patterns in the ZModel? We recently discovered an issue that invalid regex patterns can cause the "enhance function not found" error.

I don't have any regex validation pattern in my zmodel.

@Izag-Larm
Copy link
Author

I tried to rebuild my zmodel piece by piece, trying to identify each time what could cause the problem. And I get the error when I try to apply gte() validation on a field of one type.

Image

@Kylyi
Copy link

Kylyi commented Mar 11, 2025

I am having the same issue in [email protected].

All works well in dev but once built, the following happens:
[nuxt] [request error] [unhandled] [500] Generated "enhance" function not found. Please run zenstack generate first.

Somehow, when I downgrade from node@22 to node@20, it works perfectly fine.

@ymc9
Copy link
Member

ymc9 commented Mar 11, 2025

Thanks for the comments. Does anyone have a sharable repro project?

@Kylyi
Copy link

Kylyi commented Mar 11, 2025

Yup, https://github.com/Kylyi/nuxt-zenstack.

Just make sure to use node@22.
It should work in dev mode.

@Kylyi
Copy link

Kylyi commented Mar 14, 2025

This is actually starting to be a bigger issue as it somehow breaks in docker as well in some cases, even when using node@20. WIll ty to prepare another repro.

@alfredosepulveda
Copy link

Had same issue with zenstack v2.12.1 node v23 ando v22. Using node v18 fixed it.

@Kylyi
Copy link

Kylyi commented Mar 14, 2025

It seems like it's dependent on the Node specific version heavily.

Using the following Dockerfile works:
Image

while the following results in the [nuxt] [request error] [unhandled] [500] Generated "enhance" function not found. Please run zenstack generate first. issue.

Image

@sslotnick
Copy link

sslotnick commented Mar 14, 2025

I just encountered this issue going from node 20.18.3 to 20.19.0. Using the flag --no-experimental-require-module fixes it.

$ pnpm tsx --version
tsx v4.19.3
node v20.19.0
$ pnpm tsx --no-experimental-require-module ./scripts/myscript.ts
...
$ pnpm tsx ./scripts/myscript.ts
...
        throw new Error('Generated "enhance" function not found. Please run `zenstack generate` first.');
              ^
...

@ymc9
Copy link
Member

ymc9 commented Mar 20, 2025

I made a few tries with node 20.19.0 as @sslotnick indicated:

  • tsx ran into the issue, @sslotnick 's workaround worked for me
  • Nuxt ran into the issue as @Kylyi reported
  • ts-node worked fine, compiling with tsc and then running directly with node worked fine
  • Next.js worked fine

So it seems later node versions broke something related loading ESM with require, however the issue only happens with certain bundler (nuxt) and nodejs loaders (tsx) ...

I don't have further insight into the issue so far, and please use @sslotnick 's workaround for now.

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

6 participants