question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Abnormal behavior of schema.prisma outside the main folder

See original GitHub issue

Bug 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

  1. Clone https://github.com/antoineanorra/PrismaPOC
  2. Go to folder front
  3. Launch npm install
  4. 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:open
  • Created a year ago
  • Reactions:1
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
antoine-1commented, May 4, 2022

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

import { PrismaClient } from './server\db\prisma-generated'
const prisma = new PrismaClient()

but in my db folder : image

1reaction
antoine-1commented, May 4, 2022

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma schema (Reference)
The Prisma schema is the main configuration file when using Prisma. It is typically called schema.prisma and contains your database connection and data ......
Read more >
Prisma schema API (Reference)
API reference documentation for the Prisma Schema Language (PSL).
Read more >
Data model (Reference)
Learn about the concepts for building your data model with Prisma: Models, scalar types, enums, attributes, functions, IDs, default values and more.
Read more >
Generating the client (Concepts)
Important: You need to re-run the prisma generate command after every change that's made to your Prisma schema to update the generated Prisma...
Read more >
Migration troubleshooting in development
Database schema drift occurs when your database schema is out of sync with your migration history - the database schema has 'drifted away'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found