arthurfiorette / prisma-json-types-generator

⚒️ Changes JsonValues to your custom typescript type.

Home Page:https://npm.im/prisma-json-types-generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

``Cannot find module '.prisma/client'`` in pnpm workspace

nadecancode opened this issue · comments

commented
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["orderByNulls", "interactiveTransactions"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator records {
  provider = "prisma-json-types-generator"
  namespace = "PrismaJson"
  clientOutput = ".prisma/client"
}
│ database:build: Require stack:
│ database:build: - ROOT\node_modules\.pnpm\prisma-json-types-generator@1.1.2\node_modules\prisma-json-types-generator\dist\file\reader.js
│ database:build: - ROOT\node_modules\.pnpm\prisma-json-types-generator@1.1.2\node_modules\prisma-json-types-generator\dist\on-generate.js
│ database:build: - ROOT\node_modules\.pnpm\prisma-json-types-generator@1.1.2\node_modules\prisma-json-types-generator\dist\generator.js
│ database:build: - ROOT\node_modules\.pnpm\prisma-json-types-generator@1.1.2\node_modules\prisma-json-types-generator\dist\bin.js

Have you tried removing the client output and let the generator find it itself?

commented

I had this error before adding clientOutput and adding it didn't do anything.

Very weid, where are the relative locations to your prisma client output?

commented

They’re all in node_modules, just like the default location.

Can you provide a reproducible example so that I can test out?

You can also try to change this piece of code in your node modules (same path, but in the dist folder, not src)

declaration.sourcePath = overrideTarget
? overrideTarget.startsWith('./')
? path.resolve(schemaTarget!, overrideTarget)
: require.resolve(overrideTarget)
: path.resolve(
// prisma client directory
path.dirname(require.resolve('.prisma/client')),
'index.d.ts'
);

@arthurfiorette
It also does not work for me.

Here is the reproducible example:

  1. pnpm create t3-app@latest prisma-json --noGit --CI --prisma
  2. cd prisma-json
  3. pnpm install prisma-json-types-generator
  4. add the "prisma-json-types-generator" generator copied from the readme of the github repo under the prisma client generator

schema.prisma

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

generator test {
    provider     = "prisma-json-types-generator"
    namespace    = "PrismaJson"
    clientOutput = "./custom.d.ts"
}

datasource db {
    provider = "sqlite"
    url      = env("DATABASE_URL")
}

model Example {
    id        String   @id @default(cuid())
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}


  1. npx prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Error: 
✔ Generated Prisma Client (4.8.1 | library) to ./node_modules/.pnpm/@prisma+client@4.8.1_prisma@4.8.1/node_modules/@prisma/client in 24ms

ENOTDIR: not a directory, open '{path-to-project-folder}/prisma-json/prisma/schema.prisma/custom.d.ts'
  1. Remove clientOutput from schema.prisma

schema.prisma

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

generator test {
    provider     = "prisma-json-types-generator"
    namespace    = "PrismaJson"
}

datasource db {
    provider = "sqlite"
    url      = env("DATABASE_URL")
}

model Example {
    id        String   @id @default(cuid())
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}


  1. npx prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Error: 
✔ Generated Prisma Client (4.8.1 | library) to ./node_modules/.pnpm/@prisma+client@4.8.1_prisma@4.8.1/node_modules/@prisma/client in 23ms

Cannot find module '.prisma/client'
Require stack:
- {path-to-project-folder}/prisma-json/node_modules/.pnpm/prisma-json-types-generator@1.1.2/node_modules/prisma-json-types-generator/dist/file/reader.js
- {path-to-project-folder}/prisma-json/node_modules/.pnpm/prisma-json-types-generator@1.1.2/node_modules/prisma-json-types-generator/dist/on-generate.js
- {path-to-project-folder}/prisma-json/node_modules/.pnpm/prisma-json-types-generator@1.1.2/node_modules/prisma-json-types-generator/dist/generator.js
- {path-to-project-folder}/prisma-json/node_modules/.pnpm/prisma-json-types-generator@1.1.2/node_modules/prisma-json-types-generator/dist/bin.js

Finally I could reproduce it myself. Pnpm stores its dependencies under .pnpm folder and creates symbolic links from node_modules/NAME to node_modules/.pnpm/NAME@version, that's why we couldn't find .prisma folder.

The generated output should be node_modules/.pnpm/@prisma+client@4.9.0_prisma@4.9.0/node_modules/.prisma/client.

Hey @NADESHIKON & @itsyoboieltr, just released 2.0.0 with this fix.

Also, there's a new syntax for types.

model Test {
  /// [NormalType]
  field Json

  /// [OptionalType]
  field2 Json

  /// [ArrayType]
  field3 Json
}