zenstack: Can't resolve '@prisma/client/runtime' in pnpm monorepo

Description and expected behavior

I have a monorepo with the following organization. packages/db - Here I have the Zenstack setup apps/admin - A NextJs app apps/manager - A Sveltekit app

In the db package, I have the following export:

import { Prisma, PrismaClient, UserScope } from '@prisma/client';
export { enhance } from '@zenstackhq/runtime';

const env = process.env.NODE_ENV;
const isProd = env === 'production';

let prismaClient: PrismaClient | undefined;
const prisma = prismaClient || new PrismaClient();

if (isProd) prismaClient = prisma;

export { Prisma, prisma };

And my .npmrc file:

shamefully-hoist=true
node-linker=hoisted
strict-peer-dependencies=false
public-hoist-pattern[]=*prisma*
public-hoist-pattern[]=*bcrypt*
public-hoist-pattern[]=*zenstack*

In the SvelteKit app, this works great. I can reference the package, use the exported enhance, and utilize it. However, in Next.js, I’m encountering an error:

 ⚠ ../../node_modules/@zenstackhq/runtime/enhancements/utils.js
Module not found: Can't resolve '@prisma/client/runtime' in '/Users/stefanosandes/development/o3-inovacao/portal-client-o3/node_modules/@zenstackhq/runtime/enhancements'

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/enhancements/utils.js
../../node_modules/@zenstackhq/runtime/enhancements/index.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/enhancements/utils.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/enhancements/utils.js
../../node_modules/@zenstackhq/runtime/enhancements/index.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/loader.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/loader.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/loader.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/loader.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/loader.js
Module not found: Can't resolve '.zenstack/zod' in '/Users/stefanosandes/development/o3-inovacao/portal-client-o3/node_modules/@zenstackhq/runtime'

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/loader.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/version.js
Module not found: Can't resolve '../package.json' in '/Users/stefanosandes/development/o3-inovacao/portal-client-o3/node_modules/@zenstackhq/runtime'

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/version.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts
 ⚠ ../../node_modules/@zenstackhq/runtime/enhancements/utils.js
Module not found: Can't resolve '@prisma/client/runtime' in '/Users/stefanosandes/development/o3-inovacao/portal-client-o3/node_modules/@zenstackhq/runtime/enhancements'

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/enhancements/utils.js
../../node_modules/@zenstackhq/runtime/enhancements/index.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/enhancements/utils.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/enhancements/utils.js
../../node_modules/@zenstackhq/runtime/enhancements/index.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/loader.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/loader.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/loader.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/loader.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/loader.js
Module not found: Can't resolve '.zenstack/zod' in '/Users/stefanosandes/development/o3-inovacao/portal-client-o3/node_modules/@zenstackhq/runtime'

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/loader.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

../../node_modules/@zenstackhq/runtime/version.js
Module not found: Can't resolve '../package.json' in '/Users/stefanosandes/development/o3-inovacao/portal-client-o3/node_modules/@zenstackhq/runtime'

Import trace for requested module:
../../node_modules/@zenstackhq/runtime/version.js
../../node_modules/@zenstackhq/runtime/index.js
../../packages/db/prisma.ts
./src/app/(authed)/tenants/new/actions.ts

If I remove the export of enhance, the problem is resolved.

Environment (please complete the following information):

  • ZenStack version: [^1.6.2]
  • Prisma version: [^5.8.0]
  • Database type: [Postgresql]
  • Node: [v20.9.0]
  • OS: [macOs 14.2.1 (23C71)]

About this issue

  • Original URL
  • State: closed
  • Created 6 months ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Thank you for looking into it. I did some more probing and discovered that I was missing public-hoist-pattern[]=*zenstack* in my .npmrc file.

Hi @stefanosandes ,

If you’re using Next.js’s app dir, could you try if following this FAQ fixes the problem?

The runtime package is not fully compatible with the app dir bundler yet, and we plan to a full resolution in V2.

Hi @ymc9,

It works well, except when using the --turbo flag, but it is not a problem for now. Thanks for the hard work! Zenstack is a great improvement on DX, especially policies.