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

Custom Prisma Client is not working #79

Open
brandoncollins7 opened this issue Oct 5, 2023 · 14 comments
Open

Custom Prisma Client is not working #79

brandoncollins7 opened this issue Oct 5, 2023 · 14 comments

Comments

@brandoncollins7
Copy link

I am using an nx mono repo and I have my prisma models dumping to a library. So I am trying to integrate this by using a custom prisma client:

`import {PrismaClient} from '@frnt/lending-api/models'

@global()
@module({
imports: [
CustomPrismaModule.forRoot({
name: 'PrismaService',
client: new PrismaClient()
}),`

But it just seems like it is not working at all because when I run it is looking for the prisma client in node_modules?

`Error: Cannot find module '.prisma/client/index'
Require stack:

  • node_modules.pnpm@[email protected][email protected]\node_modules@prisma\client\index.js
  • node_modules.pnpm\nestjs-prisma@0.22.0_@nestjs+common@10.0.2_@prisma[email protected][email protected]\node_modules\nestjs-prisma\dist\prisma.service.js
  • node_modules.pnpm\nestjs-prisma@0.22.0_@nestjs+common@10.0.2_@prisma[email protected][email protected]\node_modules\nestjs-prisma\dist\prisma.module.js
  • node_modules.pnpm\nestjs-prisma@0.22.0_@nestjs+common@10.0.2_@prisma[email protected][email protected]\node_modules\nestjs-prisma\dist\index.js
  • dist\apps\lending-api\main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Function.Module._load (node:internal/modules/cjs/loader:920:27)
    at Function.Module._load (node_modules@nx\js\src\executors\node\node-with-require-overrides.js:18:31)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object. (node_modules@[email protected][email protected]\node_modules@prisma\client\index.js:2:6)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.Module._load (node_modules@nx\js\src\executors\node\node-with-require-overrides.js:18:31)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object. (node_modules\nestjs-prisma\lib\prisma.service.ts:9:1)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1308:10)

`

@marcjulian
Copy link
Member

Hi @brandoncollins7, how are you accessing the database are you using CustomPrismaService? Do you have a reproduction repository, which would be easier to help if i can reproduce it myself.

@marcjulian
Copy link
Member

I cannot reproduce it atm. Please provide a reproduction repo.

@tomcastro
Copy link

Hi @marcjulian, I'm having the same issue but with a PNPM and Turborepo monorepo. I am using CustomPrismaService<PrismaClient> with my PrismaClient exported from the output.

I have tried both exporting the custom output to node_modules as specified on the documentation as well as on a folder inside my src directory, but it seems that nestjs-prisma is trying to import the default @prisma/client and it cannot find it (prisma generate creates the Prisma client on the specified custom output). I'm attaching the error:

test:start:dev: Error: Cannot find module '.prisma/client/index'
test:start:dev: Require stack:
test:start:dev: - /Users/tomascastro/Code/org/org-svcs/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/index.js
test:start:dev: - /Users/tomascastro/Code/org/org-svcs/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]/node_modules/nestjs-prisma/dist/prisma.service.js
test:start:dev: - /Users/tomascastro/Code/org/org-svcs/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]/node_modules/nestjs-prisma/dist/prisma.module.js
test:start:dev: - /Users/tomascastro/Code/org/org-svcs/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]/node_modules/nestjs-prisma/dist/index.js
test:start:dev: - /Users/tomascastro/Code/org/org-svcs/apps/test/dist/app.module.js
test:start:dev: - /Users/tomascastro/Code/org/org-svcs/apps/test/dist/main.js
test:start:dev:     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
test:start:dev:     at Module.Hook.Module.require (/Users/tomascastro/Code/org/org-svcs/node_modules/.pnpm/[email protected]/node_modules/dd-trace/packages/dd-trace/src/ritm.js:54:29)
test:start:dev:     at require (node:internal/modules/helpers:130:18)
test:start:dev:     at Object.<anonymous> (/Users/tomascastro/Code/org/org-svcs/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/index.js:2:6)
test:start:dev:     at Module._compile (node:internal/modules/cjs/loader:1233:14)
test:start:dev:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
test:start:dev:     at Module.load (node:internal/modules/cjs/loader:1091:32)
test:start:dev:     at Function.Module._load (node:internal/modules/cjs/loader:938:12)
test:start:dev:     at Module.require (node:internal/modules/cjs/loader:1115:19)
test:start:dev:     at Module.Hook.Module.require (/Users/tomascastro/Code/org/org-svcs/node_modules/.pnpm/[email protected]/node_modules/dd-trace/packages/dd-trace/src/ritm.js:85:33)
generator client {
  provider = "prisma-client-js"
  output   = "../node_modules/@org/client"
}

app.module.ts

import { CustomPrismaModule } from 'nestjs-prisma';
import { PrismaClient } from '@org/client';

...
CustomPrismaModule.forRoot({
  name: 'PrismaService',
  client: new PrismaClient(),
  isGlobal: true,
}),

I can help providing a small repo to reproduce, but that will take a bit of time. Maybe this can help in the meantime? 😄

@marcjulian
Copy link
Member

Thanks for the error logs. Looks like PrismaService, which is in the package is trying to access the default prisma client. I will add an example and see if I can reproduce the same error.

@marcjulian marcjulian reopened this Oct 18, 2023
@marcjulian
Copy link
Member

marcjulian commented Oct 18, 2023

It looks like that this is caused because of the index.ts exporting all files from the library, even though PrismaService is not used it imports from @prisma/client.

I guess the import need to change e.g.

- import { CustomPrismaModule } from 'nestjs-prisma';
+ import { CustomPrismaModule } from 'nestjs-prisma/custom';

export * from './custom';
export * from './prisma.module';
export * from './prisma.service';

A current workaround would be to change the imports too

import { CustomPrismaModule } from 'nestjs-prisma/dist/custom';
import { CustomPrismaService } from 'nestjs-prisma/dist/custom';

@Valetek
Copy link

Valetek commented Nov 9, 2023

Hi, thanks for the workaround, but it's seem we can't use the PrismaClientExceptionFilter with this (as it's also require prisma/client)

Do you think it will be possible in the near future to use all the feature with a custom client ? or is there also another workaround for this case ?

Krr0ptioN added a commit to Krr0ptioN/musica that referenced this issue Nov 22, 2023
Incorrect temptation to import the default client instead of utilizing the provided custom client.
**This solution is temporary!** Until nestjs-prisma new release.

Related Links to the issue:
- notiz-dev/nestjs-prisma#79
@Krr0ptioN
Copy link

I am facing the same issue, I managed to solve this issue with workaround (thanks to @marcjulian), although I am not sure whether this is a stable or temporary solution.

My stack:

  • Nx, typescript
  • Custom Prisma Client path

@Valetek
Copy link

Valetek commented Nov 22, 2023

@Krr0ptioN Could you share / show how you did your workaround ?

@marcjulian
Copy link
Member

marcjulian commented Nov 22, 2023

@Valetek have you tried this workaround? #79 (comment) I think @Krr0ptioN means that workaround.

@Valetek
Copy link

Valetek commented Nov 22, 2023

HO yes this one, finally I used the setup for custom config (with prisma module) and everything is working fine, except that I used my own custom FilterException

I did tried this workaround but it's still fail when calling the prismaFilterException

@marcjulian
Copy link
Member

Yes PrismaClientExceptionFilter does not currently work for custom location. I will have a look on a fix for that as well.

@Krr0ptioN
Copy link

@Valetek this workaround

@marcjulian
Copy link
Member

I am facing the same issue, I managed to solve this issue with workaround (thanks to @marcjulian), although I am not sure whether this is a stable or temporary solution.

My stack:

  • Nx, typescript
  • Custom Prisma Client path

This is currently a temporary solution. When I have the time I would like to move all exports related to custom prisma service under nestjs-prisma/custom.

Krr0ptioN added a commit to Krr0ptioN/musica that referenced this issue Dec 2, 2023
* feat: setup prisma and database

* add: createdAt and updateAt for collections

* feat(dev): swagger, cors, hemlet, config

* fix(prisma): custom prisma client

* fix: PrismaCustomClient injection

* fix: versioning correction


* feat(module/music): CRUD with basic api documentation

* feat: utils for logging

* fix: api URI naming

* fix(db/music): optional attribute

* add(config): default storage directory for music upload destinationn

* add(utils): audio file filteration for upload validation

* add(utils): music file generator

* feat(db): unique filename for uploaded music file

* add(package): mutler and express for file upload

* feat(module/music): music file upload while creating music

* chore: changing prisma output directory

* chore: prisma library import path for new client output directory

Related commits:
- 472612f

* add: necessary packages for file upload

* chore: ignore prisma client generation

* fix(db|tmp): CustomPrismaClient issue

Incorrect temptation to import the default client instead of utilizing the provided custom client.
**This solution is temporary!** Until nestjs-prisma new release.

Related Links to the issue:
- notiz-dev/nestjs-prisma#79

* fix(module/music): invalid request - No file is provided

* fix(module/music): create upload folder if it doesn't exist in the current container system

* fix(module/music): file filteration and standard response

* fix(module/music): parse the complex query request

* refactor(module/music): query input validation and parsing

* fix(module/music): using same file name

- The controller create another filename instead of reusing what mutler provided

* feat(module/music): stream music file

* test(e2e): music creation

* fix(test): api hello world

* fix(test): server config

* chore: add form data

* chore: clean up

* refactor(module/music): clean response and debug message

* refactor(test):  music creation

- Utils for file stream creation
- Central mock data collection
- Renamed test

* refactor(module/music): e2e

* refactor(module/music): e2e

* refactor(api): use supertest for e2e
Krr0ptioN added a commit to Krr0ptioN/musica that referenced this issue Dec 2, 2023
* feat: music player widget

* chore: correct naming convetion

* chore: clean up

* feat(ui): music player pause and play

* feat(ui): design system & colorscheme

* chore: clean up

* feat(ui): music player

* feat: setup prisma and database

* add: createdAt and updateAt for collections

* feat(dev): swagger, cors, hemlet, config

* fix(prisma): custom prisma client

* fix: PrismaCustomClient injection

* fix: versioning correction

* chore: lint

* chore: lint

* feat(module/music): CRUD with basic api documentation

* feat: utils for logging

* fix: api URI naming

* fix(db/music): optional attribute

* add(config): default storage directory for music upload destinationn

* add(utils): audio file filteration for upload validation

* add(utils): music file generator

* feat(db): unique filename for uploaded music file

* add(package): mutler and express for file upload

* feat(module/music): music file upload while creating music

* chore: changing prisma output directory

* chore: prisma library import path for new client output directory

Related commits:
- 472612f

* add: necessary packages for file upload

* chore: ignore prisma client generation

* chore: lint & cleanup

* fix(db|tmp): CustomPrismaClient issue

Incorrect temptation to import the default client instead of utilizing the provided custom client.
**This solution is temporary!** Until nestjs-prisma new release.

Related Links to the issue:
- notiz-dev/nestjs-prisma#79

* fix(module/music): invalid request - No file is provided

* fix(module/music): create upload folder if it doesn't exist in the current container system

* fix(module/music): file filteration and standard response

* fix(module/music): parse the complex query request

* refactor(module/music): query input validation and parsing

* fix(module/music): using same file name

- The controller create another filename instead of reusing what mutler provided

* feat(module/music): stream music file

* test(e2e): music creation

* fix(test): api hello world

* fix(test): server config

* chore: lint

* chore: add form data

* chore: clean up

* refactor(module/music): clean response and debug message

* refactor(test):  music creation

- Utils for file stream creation
- Central mock data collection
- Renamed test

* chore: gitignore update

* feat: utils for api request in frontend

* feat: music type for store and api

* feat(music-player): action hook

* feat(music-player): redux store for music player

* feat(music-player): refactor the complicated div design to slider

* feat(music-player): next and previous button

* feat(music-player): redux store instead of state

* feat(music-player): next and previous redux action creator

* refactor(module/music): e2e

* refactor(module/music): e2e

* refactor(api): use supertest for e2e

* lint

* add: docker compose
@stormsilver
Copy link

I just ran into this problem and the workaround still seems valid, although the path has changed slightly:

import { CustomPrismaModule } from 'nestjs-prisma/dist/custom';

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