zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

Can't resolve '@prisma/client/runtime' in pnpm monorepo #944

Closed stefanosandes closed 7 months ago

stefanosandes commented 9 months ago

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):

ymc9 commented 9 months ago

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.

stefanosandes commented 9 months ago

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.

ymc9 commented 9 months ago

Thanks for confirming @stefanosandes , and I'm glad you find ZenStack helpful!

I'm closing this issue for now.

stefanosandes commented 8 months ago

Hey @ymc9, sorry for commenting here again.

The same error occurred when I imported the client into the NextAuth config.

My auth.ts file:

import NextAuth from 'next-auth';
import Credentials from 'next-auth/providers/credentials';
import { prisma } from '@portalo3/db';

export const {
    auth,
    signIn,
    signOut,
    handlers: { GET, POST }
} = NextAuth({
    pages: {
        signIn: '/login'
    },
    callbacks: {
        authorized({ auth, request: { nextUrl } }) {
            const isLoggedIn = !!auth?.user;
            const path = nextUrl.pathname;
            const isProtectedRoute = !(
                path.startsWith('/login') ||
                path.startsWith('/forgot-password') ||
                path.startsWith('/logout')
            );

            if (isProtectedRoute) {
                if (isLoggedIn) return true;
                return Response.redirect(new URL('/login', nextUrl), 303);
            } else if (isLoggedIn) {
                return Response.redirect(new URL('/', nextUrl), 303);
            }
        }
    },
    providers: [
        Credentials({
            credentials: {
                username: { label: 'Usuário', type: 'text' },
                password: { label: 'Senha', type: 'password' }
            },
            name: 'Credentials',
            async authorize(credentials, req) {
                if (!credentials.password || !credentials.username) {
                    return null;
                }

                console.log(prisma);

                return null;
            }
        })
    ]
});

The returned error:


⚠ Fast Refresh had to perform a full reload due to a runtime 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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.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/index.ts
./src/auth.server.ts
 ⨯ Error [ReferenceError]: runtimeDescription is not defined
    at <unknown> (webpack-internal:///(middleware)/../../node_modules/.prisma/client/index-browser.js:67)
    at Prisma.defineExtension (webpack-internal:///(middleware)/../../node_modules/.prisma/client/index-browser.js:67:71)
    at eval (webpack-internal:///(middleware)/../../packages/db/prisma/extensions/user-portal.ts:9:75)
    at (middleware)/../../packages/db/prisma/extensions/user-portal.ts (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/src/middleware.js:2497:1)
    at __webpack_require__ (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/edge-runtime-webpack.js:37:33)
    at fn (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/edge-runtime-webpack.js:280:21)
    at eval (webpack-internal:///(middleware)/../../packages/db/index.ts:10:88)
    at (middleware)/../../packages/db/index.ts (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/src/middleware.js:2486:1)
    at __webpack_require__ (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/edge-runtime-webpack.js:37:33)
    at fn (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/edge-runtime-webpack.js:280:21)
    at eval (webpack-internal:///(middleware)/./src/auth.server.ts:11:70) {
  middleware: true
}
 ⨯ Error [ReferenceError]: runtimeDescription is not defined
    at <unknown> (webpack-internal:///(middleware)/../../node_modules/.prisma/client/index-browser.js:67)
    at Prisma.defineExtension (webpack-internal:///(middleware)/../../node_modules/.prisma/client/index-browser.js:67:71)
    at eval (webpack-internal:///(middleware)/../../packages/db/prisma/extensions/user-portal.ts:9:75)
    at (middleware)/../../packages/db/prisma/extensions/user-portal.ts (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/src/middleware.js:2497:1)
    at __webpack_require__ (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/edge-runtime-webpack.js:37:33)
    at fn (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/edge-runtime-webpack.js:280:21)
    at eval (webpack-internal:///(middleware)/../../packages/db/index.ts:10:88)
    at (middleware)/../../packages/db/index.ts (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/src/middleware.js:2486:1)
    at __webpack_require__ (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/edge-runtime-webpack.js:37:33)
    at fn (file:///Users/stefanosandes/development/o3-inovacao/portal-client-o3/apps/admin/.next/server/edge-runtime-webpack.js:280:21)
    at eval (webpack-internal:///(middleware)/./src/auth.server.ts:11:70) {
  middleware: true
}

These errors do not occur when I import Prisma Client on pages or actions, only when I import them in auth.ts. This file is imported in middleware.ts to define a protected middleware. Is there any relation?

ymc9 commented 8 months ago

Hi @stefanosandes , which version of NextJS are you using? Do you use standard runtime or the edge runtime?

I suspect this has something to do with this bug. It seems in some cases newer version of NextJS doesn't respect the "serverComponentsExternalPackages" option ...

Azzerty23 commented 8 months ago

These errors do not occur when I import Prisma Client on pages or actions, only when I import them in auth.ts. This file is imported in middleware.ts to define a protected middleware. Is there any relation?

@prisma/client/runtime is not edge compatible. Ensure not to import it into your middleware (edge runtime on Vercel) by keeping auth.config.ts separate from auth.ts: https://authjs.dev/guides/upgrade-to-v5#edge-compatibility

stefanosandes commented 8 months ago

@ymc9 I'm using 14.0.4. @Azzerty23 I think it's not related. Everything works by importing the Prisma client from a file that does not import Zenstack. And I'm not using database adapters; I'm just relying on the Credentials provider's authorize method. This error occurs specifically when I import the Prisma client from the same file where I export the Zenstack enhance method.

Azzerty23 commented 8 months ago

The error reminded me of an issue I had faced myself. I have created a similar project to yours: https://github.com/Azzerty23/zenstack-create-t3-turbo-app-router. It's not perfect, I need to update some packages, but it works. Perhaps you will identify the problem by comparing our two projects.

Azzerty23 commented 8 months ago

I just tested it. This error occurs when you don't add the serverComponentsExternalPackages in the next.config.mjs file, as @ymc9 mentioned earlier:

  experimental: {
    serverComponentsExternalPackages: ["@zenstackhq/runtime"],
  },
ymc9 commented 8 months ago

method.

I guess there's some strange thing going on with nextjs bundler in your case if you already configured the "serverComponentsExternalPackages" option.

Is there a shareable repo I can look into?

ErikDakoda commented 7 months ago

Hello!

I just rebuilt my monorepo and now I am getting the same error:

○ Compiling /api/model/[...path] ... ⚠ ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/enhancements/utils.js Module not found: Can't resolve '@prisma/client/runtime' in '/Users/erik/Dev/uvilo-mono/node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/enhancements'

Import trace for requested module: ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/enhancements/utils.js ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/enhancements/index.js ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/index.js ../../packages/@erikdakoda/database/server/getEnhancedPrisma.ts ./src/pages/api/model/[...path].ts

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

Import trace for requested module: ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/enhancements/utils.js ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/enhancements/index.js ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/index.js ../../packages/@erikdakoda/database/server/getEnhancedPrisma.ts ./src/pages/api/model/[...path].ts

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

Import trace for requested module: ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/loader.js ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/index.js ../../packages/@erikdakoda/database/server/getEnhancedPrisma.ts ./src/pages/api/model/[...path].ts

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

Import trace for requested module: ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/loader.js ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/index.js ../../packages/@erikdakoda/database/server/getEnhancedPrisma.ts ./src/pages/api/model/[...path].ts

../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/loader.js Module not found: Can't resolve '.zenstack/zod' in '/Users/erik/Dev/uvilo-mono/node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime'

Import trace for requested module: ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/loader.js ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/index.js ../../packages/@erikdakoda/database/server/getEnhancedPrisma.ts ./src/pages/api/model/[...path].ts

../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/version.js Module not found: Can't resolve '../package.json' in '/Users/erik/Dev/uvilo-mono/node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime'

Import trace for requested module: ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/version.js ../../node_modules/.pnpm/@zenstackhq+runtime@1.9.0/node_modules/@zenstackhq/runtime/index.js ../../packages/@erikdakoda/database/server/getEnhancedPrisma.ts ./src/pages/api/model/[...path].ts

ymc9 commented 7 months ago

Critical dependency: the request of a dependency is an expression

Hi @ErikDakoda , what version of NextJS are you using? Is it a pure pages route project or does it also use apps route? Does the build eventually succeed despite the error messages?

I may need a repro project to fully understand what's going one ...

ErikDakoda commented 7 months ago

Hi @ymc9! Thank you for your help. This is a pages router project, though I do have an app directory with a couple of API routes that use the Vercel ai package that is required to be there - but they don't use Prisma or ZenStack. My app builds and runs, data is even loaded to the client, but what fails is compiling the API model route that calls @zenstackhq/server/next. Here are my versions:

"next": "14.1.0",
"@planetscale/database": "1.16.0",
"@prisma/adapter-planetscale": "5.9.1",
"@prisma/client": "5.7.1",
"@zenstackhq/runtime": "1.9.0",
"@zenstackhq/server": "1.9.0",
"db": "link:prisma/client"
"@zenstackhq/tanstack-query": "1.9.0",
"prisma": "5.7.1",
"zenstack": "1.9.0"

BTW, do you publish the latest tested supported versions of next, prisma, etc? I will give you temporary access to my repo.

ymc9 commented 7 months ago

Hi @ymc9! Thank you for your help. This is a pages router project, though I do have an app directory with a couple of API routes that use the Vercel ai package that is required to be there - but they don't use Prisma or ZenStack. My app builds and runs, data is even loaded to the client, but what fails is compiling the API model route that calls @zenstackhq/server/next. Here are my versions:

"next": "14.1.0",
"@planetscale/database": "1.16.0",
"@prisma/adapter-planetscale": "5.9.1",
"@prisma/client": "5.7.1",
"@zenstackhq/runtime": "1.9.0",
"@zenstackhq/server": "1.9.0",
"db": "link:prisma/client"
"@zenstackhq/tanstack-query": "1.9.0",
"prisma": "5.7.1",
"zenstack": "1.9.0"

BTW, do you publish the latest tested supported versions of next, prisma, etc? I will give you temporary access to my repo.

Thanks for granting me with access @ErikDakoda . When I build the repo, I got an error with "nextjs-monorepo-workaround-plugin".

Error: Cannot find module '.prisma/client'
Require stack:
- /Users/yiming/git/repro/uvilo-mono/node_modules/.pnpm/@prisma+nextjs-monorepo-workaround-plugin@5.6.0/node_modules/@prisma/nextjs-monorepo-workaround-plugin/index.js
- /Users/yiming/git/repro/uvilo-mono/apps/bot-craft/next.config.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at /Users/yiming/git/repro/uvilo-mono/node_modules/.pnpm/next@14.0.3_@babel+core@7.23.3_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/require-hook.js:54:36
    at Function.resolve (node:internal/modules/helpers:187:19)
    at getPrismaDir (/Users/yiming/git/repro/uvilo-mono/node_modules/.pnpm/@prisma+nextjs-monorepo-workaround-plugin@5.6.0/node_modules/@prisma/nextjs-monorepo-workaround-plugin/index.js:18:31)
    at async /Users/yiming/git/repro/uvilo-mono/node_modules/.pnpm/@prisma+nextjs-monorepo-workaround-plugin@5.6.0/node_modules/@prisma/nextjs-monorepo-workaround-plugin/index.js:66:33
    at async Promise.all (index 14)
    at async /Users/yiming/git/repro/uvilo-mono/node_modules/.pnpm/@prisma+nextjs-monorepo-workaround-plugin@5.6.0/node_modules/@prisma/nextjs-monorepo-workaround-plugin/index.js:95:11

Do you see the same thing? I haven't seen the error from zenstack yet.

ErikDakoda commented 7 months ago

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.