prisma: `prisma generate`, typings not updating in VSCode unless IDE is restarted.

Bug description

Changing the type of a field in a model, or adding a new field, then running the command npx prisma db push and npx prisma generate are not updating the typings in my IDE, unless I restart VSCode after making my schema changes and running those commands.

During prototyping where I am frequently updating my models, this disrupts my workflow significantly.

How to reproduce

  1. Add a new field to a model
  2. Run npx prisma db push and npx prisma generate
  3. The field created in step 1 will not be recognized when executing await prisma.model.create(data: {…}).
  4. Restart VSCode
  5. Step 3 error goes away.

Expected behavior

The IDE recognizes the updates to the model and does not require a restart.

Prisma information

<!-- Do not include your database credentials when sharing your Prisma schema! -->
// 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"
}

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

model YoutubeAccount {
  username        String          @unique
  password        String
  profile_path    String
  proxy           String
  video_templates VideoTemplate[]
}

model VideoTemplate {
  id                     Int             @id @default(autoincrement())
  inputDirs              String[]
  title                  String
  description            String
  tags                   String[]
  clipCount              Int
  duration               Int
  width                  Int
  height                 Int
  YoutubeAccount         YoutubeAccount? @relation(fields: [youtubeAccountUsername], references: [username])
  youtubeAccountUsername String?
}

Environment & setup

  • OS:
  • Windows
  • Database:
  • PostgreSQL
  • Node.js version:
  • Node 18.4.0

Prisma Version

npx prisma -v
Environment variables loaded from .env
prisma                  : 4.2.0
@prisma/client          : 4.2.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt 2920a97877e12e055c1333079b8d19cee7f33826 (at 
node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : 2920a97877e12e055c1333079b8d19cee7f33826
Studio                  : 0.469.0

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 16
  • Comments: 38 (15 by maintainers)

Most upvoted comments

FWIW, I just noticed today that TypeScript: Restart TS Server is now being run automatically whenever I run prisma generate, which is a first for me! I’m on Linux Mint.

Very convenient 😃

Opening up the definition file by pressing F12 over a referenced type will fix it so there’s not need to restart. Not the best solution I know but I thought I’d mention it until a real fix comes up.

This bug is easy to reproduce. Just add a new field to any model that has been already pushed to database. Push the new model to database. Now the VS CODE will show an error when you do any operation using PRISMA with the new field. It’s says that the field doesn’t belong to Prisma. The bug goes away if you close and reopen the project vs code files.

Note, like Jan said, the Prisma VS Code extension handles that automatically.

Also, you don’t need to restart VS Code, this one from the command palette will do it perfectly: “TypeScript: Restart TS Server” See https://stackoverflow.com/a/64456017/1345244 for example and shortcut.

Do you have the Prisma VSCode extension installed? We have some code that tries to work around this problem (which btw is not directly Prisma related, but just how the TS server works unfortunately) by restarting the TS server when we detect a change of the types.

Tell that to VS Code and the TS language server. We certainly agree 😄

We assume the problem is caused by Prisma generating the files to node_modules/.prisma by default, but have not figured out or confirmed for that to be the case. Let us know if using a custom output in the generator block makes the problem go away.

If you run “yarn build” and update your dependencies in the node_modules there’s a good chance TS server will catch the changes. What is the difference when it comes to node_modules/.prisma?

I have the extension and didn’t notice that it’s doing so. Cool to know though, I’ll be looking to see if I can reproduce it not being reloaded.

Doing it manually is a really small trade-off for how amazing this package is!

Hi @Jolg42 I have tried 5.9.1-dev.1 and it works

Same with me…

Try to uninstall and install the extention but still got issue. Wanna to restart TS but command pallet not appear . I must be manually delete my node_modules file and install again.

Very exhausted if every change prisma schema should manually delete node module.

I’m use MAC OS Somona and latest VScode btw.

any other solution work for this?

@janpio Thank you for the hint… I’ve just assumed, that the checkbox will activate watch mode. But I took a closer look today… It is indeed confusing 😄

So i tried it with the checkbox activated as well as deactivated, restarted VS Code before making changes to the schema file. But without luck. Maybe I’m doing it all wrong, so here is my workflow:

  • Adding NewModel to schema.prisma
  • npx prisma db push (console says client is generated, all in sync)
  • Adding a prisma.newModel.findUnique() call to a ts-file
  • getting a typescript error because newModel does not exist
  • restarting TS Server manually
  • TS Error is gone

I won’t go crazy with restarting the server manually all the time, but if the extension is expected to handle this, it shoud work 😉

@joaopedrodcf If you install the Prisma VS Code extension it will automatically trigger the “Restart TS server” command when a change is detected.

@joaopedrodcf @younes-alouani Did you try Prisma’s VS Code extension? Is it working for you?

Alternatively, you can also trigger the same command manually via the command palette: Screenshot 2022-12-07 at 10 01 55

Hi, just wanted to let you know that I do have the Prisma extension added to VS Code. @Jolg42 Good to know about the steps you mentioned to also fix this, thanks.