Abnormal behavior of schema.prisma outside the main folder
See original GitHub issueBug description
When schema.prisma file is located outside the main folder, when npx prisma generate, it will install node_modules, package*.json next to schema.prisma file.
Exemple :
Folder frontAPI Folder adminAPI Folder db (only schema.prisma file)
$ npx prisma generate --schema="../db/schema.prisma"
Environment variables loaded from .env
Prisma schema loaded from ..\db\schema.prisma
✔ Generated Prisma Client (3.13.0 | library) to .\..\db\node_modules\@prisma\client in 59ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
```
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
```
As you can see, it has generated the node_modules in the db folder. However it tells me to import prisma from “@prisma/client” even though it has installed it elsewhere.
Even if I put the “output” (in generator block) instruction in the schema.prisma to tell it to install it in the frontAPI folder, it still installs the node_modules in the db folder
How to reproduce
- Clone https://github.com/antoineanorra/PrismaPOC
- Go to folder front
- Launch npm install
- Launch npx prisma generate
You can see in the db folder, node_modules, package*.json created in wrong place.
Expected behavior
When you specify a schema.prisma that is outside the main folder, or when you specify the output instruction, you should have the installation of the @prisma/client in the main folder and not in the folder where there is just the schema
Prisma information
// 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"
output = "../front/server/db/prisma-generated"
}
datasource db {
provider = "sqlite"
url = "file:./dev.db"
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
Environment & setup
- OS: tested on Windows & Docker
- Database: tested on SQLite, MySQL, MariaDB
- Node.js version: v16.15.0
Prisma Version
prisma : 3.13.0
@prisma/client : 3.13.0
Current platform : windows
Query Engine (Node-API) : libquery-engine efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine : migration-engine-cli efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : efdf9b1183dddfd4258cd181a72125755215ab7b
Studio : 0.459.0
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:21 (9 by maintainers)
Top GitHub Comments
I redid a clone, I went to front, I did an npm install then I ran npx prisma generate --schema=“…/db/schema.prisma”
PS C:\Users\Admin\Desktop\clone\PrismaPOC\front> npx prisma generate --schema=“…/db/schema.prisma” Prisma schema loaded from …\db\schema.prisma
✔ Generated Prisma Client (3.13.0 | library) to .\server\db\prisma-generated in 255ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
but in my db folder :
I ran the command npm init -y in the root folder and this is what happened.
Instead of generating the node_modules & package*.json in the “db” folder, it creates them in the root folder yes.
So still the same problem, it doesn’t generate in the right place (because my project is in the “front” subfolder)