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

[BUG] - @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again #515

Closed
mattvan83 opened this issue Jan 14, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@mattvan83
Copy link

Description

When trying to install nextAdmin manually with pre-existing mongoDB, I got the following error message when trying to go to the /admin page:

⨯ ./src/app/admin/[[...nextadmin]]/page.tsx:3:1
Module not found: Can't resolve '@/prisma'
 1 | import { NextAdmin, PageProps } from "@premieroctet/next-admin";
 2 | import { getNextAdminProps } from "@premieroctet/next-admin/appRouter";
> 3 | import { prisma } from "@/prisma";
   | ^
 4 | import "@/app/globals.css"; // .css file containing tailiwnd rules
 5 |
 6 | export default async function AdminPage({ params, searchParams }: PageProps) {

https://nextjs.org/docs/messages/module-not-found

Reproduction URL

https://github.com/mattvan83/lcdbp-frontend/tree/pprod

Reproduction steps

1. Follow the steps defined here: https://next-admin-docs.vercel.app/docs/getting-started

I defined the Tailwind rules in @/app/globals.css file.

I got back Prisma models and types from the pre-existing mongoDB.

Next router

App router

Next Admin version

7.1.1

Screenshots

![DESCRIPTION](LINK.png)

Next Admin options

No response

Logs

No response

Browsers

Chrome

@mattvan83 mattvan83 added the bug Something isn't working label Jan 14, 2025
@cregourd
Copy link
Collaborator

Hi @mattvan83, the current documentation of manual installation suppose that your Next.js project is using aliases for imports and modules, probably your issue comes from that your project isn't. To fix your issue, try to import { prisma } from your Prisma file by using a relative (or absolute - if configured) path

@mattvan83
Copy link
Author

mattvan83 commented Jan 17, 2025

Hi @cregourd I have added a prisma.ts file in @/lib/ folder:

import { PrismaClient } from "@prisma/client";

const globalForPrisma = global as unknown as { prisma: PrismaClient };

export const prisma =
  globalForPrisma.prisma ||
  new PrismaClient({
    log: ["query", "info", "warn", "error"],
  });

if (process.env.NODE_ENV !== "production") {
  globalForPrisma.prisma = prisma;
}

Then whenever I try to access /admin or /admin/users page, I got the following error:

 ⨯ Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
    at new PrismaClient (/Users/matthieu/Code/Web/LCDBP/lcdbp-frontend/node_modules/.prisma/client/default.js:43:11)
    at eval (webpack-internal:///(rsc)/./src/lib/prisma.ts:9:42)
    at (rsc)/./src/lib/prisma.ts (/Users/matthieu/Code/Web/LCDBP/lcdbp-frontend/.next/server/app/(admin)/admin/[[...nextadmin]]/page.js:410:1)
    at __webpack_require__ (/Users/matthieu/Code/Web/LCDBP/lcdbp-frontend/.next/server/webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./src/app/(admin)/admin/[[...nextadmin]]/page.tsx:9:69)
    at (rsc)/./src/app/(admin)/admin/[[...nextadmin]]/page.tsx (/Users/matthieu/Code/Web/LCDBP/lcdbp-frontend/.next/server/app/(admin)/admin/[[...nextadmin]]/page.js:359:1)
    at Function.__webpack_require__ (/Users/matthieu/Code/Web/LCDBP/lcdbp-frontend/.next/server/webpack-runtime.js:33:43)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async collectGenerateParams (/Users/matthieu/Code/Web/LCDBP/lcdbp-frontend/node_modules/next/dist/build/utils.js:921:21)
    at async Object.loadStaticPaths (/Users/matthieu/Code/Web/LCDBP/lcdbp-frontend/node_modules/next/dist/server/dev/static-paths-worker.js:46:13) {
  type: 'Error',
  page: '/admin'
}
 ○ Compiling /_error ...
 ✓ Compiled /_error in 1717ms (5862 modules)

I have however run yarn prisma generate, which generated a schema.json file in ./nodes_modules/nodes_modules/.next-admin folder:

yarn prisma generate
yarn run v1.22.21
$ /Users/matthieu/Code/Web/LCDBP/lcdbp-frontend/node_modules/.bin/prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Next Admin JSON Schema Generator to ./node_modules/node_modules/.next-admin in 8ms

✨  Done in 3.20s.
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "contacts": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "__nextadmin": {
            "primaryKey": true,
            "kind": "scalar",
            "type": "String",
            "disabled": true,
            "required": true,
            "isList": false
          }
        },
        "v": {
          "type": "integer",
          "__nextadmin": {
            "primaryKey": false,
            "kind": "scalar",
            "type": "Int",
            "disabled": false,
            "required": true,
            "isList": false
          }
        },
        "createdAt": {
          "type": "string",
          "format": "date-time",
          "__nextadmin": {
            "primaryKey": false,
            "kind": "scalar",
            "type": "DateTime",
            "disabled": false,
            "required": true,
            "isList": false
          }
        },
        "email": {
          "type": "string",
          "__nextadmin": {
            "primaryKey": false,
            "kind": "scalar",
            "type": "String",
            "disabled": false,
            "required": true,
            "isList": false
          }
        },
        "firstname": {
          "type": "string",
          "__nextadmin": {
            "primaryKey": false,
            "kind": "scalar",
            "type": "String",
            "disabled": false,
            "required": true,
            "isList": false
          }
        },
        "lastname": {
          "type": "string",
          "__nextadmin": {
            "primaryKey": false,
            "kind": "scalar",
            "type": "String",
            "disabled": false,
            "required": true,
            "isList": false
          }
        },
        "message": {
          "type": "string",
          "__nextadmin": {
            "primaryKey": false,
            "kind": "scalar",
            "type": "String",
            "disabled": false,
            "required": true,
            "isList": false
          }
        },
        "ownCopy": {
          "type": "boolean",
          "__nextadmin": {
            "primaryKey": false,
            "kind": "scalar",
            "type": "Boolean",
            "disabled": false,
            "required": true,
            "isList": false
          }
        },
        "phone": {
          "type": "string",
          "__nextadmin": {
            "primaryKey": false,
            "kind": "scalar",
            "type": "String",
            "disabled": false,
            "required": true,
            "isList": false
          }
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time",
          "__nextadmin": {
            "primaryKey": false,
            "kind": "scalar",
            "type": "DateTime",
            "disabled": false,
            "required": true,
            "isList": false
          }
        }
      },
      "required": [
        "v",
        "createdAt",
        "email",
        "firstname",
        "lastname",
        "message",
        "ownCopy",
        "phone",
        "updatedAt"
      ]
    }
  },
  "type": "object",
  "properties": {
    "contacts": {
      "$ref": "#/definitions/contacts"
    }
  }
}

So I commented this line in ./prisma/client/default.js file:

// src/scripts/default-index.ts
var PrismaClient = class {
  constructor() {
    // throw new Error('@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.');
  }
};

But once done I have this error:

 ⨯ Internal error: TypeError: Cannot use 'in' operator to search for 'undefined' in undefined
    at preparePrismaListRequest (./node_modules/@premieroctet/next-admin/dist/utils/prisma.js:221:20)
    at async fetchDataList (./node_modules/@premieroctet/next-admin/dist/utils/prisma.js:304:31)
    at async getMappedDataList (./node_modules/@premieroctet/next-admin/dist/utils/prisma.js:396:47)
    at async getPropsFromParams (./node_modules/@premieroctet/next-admin/dist/utils/props.js:81:44)
digest: "2120126688"
 GET /admin/users 200 in 818ms

Thanks for helping!

@mattvan83 mattvan83 changed the title [BUG] - Module not found: Can't resolve '@/prisma' [BUG] - @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again Jan 17, 2025
@mattvan83
Copy link
Author

Solved! I have unfortunately deleted this part in schema.prisma...:

generator client {
  provider = "prisma-client-js"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants