prisma: `EPERM: operation not permitted, unlink '...node_modules\prisma\query_engine-windows.dll.node'`

Bug description

Following the Getting Started guide, when it gets to the point of running the “migrate dev” command, the script tries to install some packages through npm (don’t know which ones) and this causes the error in title.

How to reproduce

  1. Follow the Getting started prisma guide up to and included the “npx prisma migrate dev --name init” command.
  2. Get the following error:
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "testprisma", schema "public" at "localhost:5432"

PostgreSQL database testprisma created at localhost:5432

The following migration(s) have been created and applied from new schema changes:

migrations/
  └─ 20210909080511_init/
    └─ migration.sql

Your database is now in sync with your schema.

Running generate... (Use --skip-generate to skip the generators)
npm WARN hello-prisma@1.0.0 No description
npm WARN hello-prisma@1.0.0 No repository field.

npm ERR! code EPERM
npm ERR! syscall unlink
npm ERR! path C:\Users\mbelletti\Documents\Projects\hello-prisma\node_modules\prisma\query_engine-windows.dll.node
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Users\mbelletti\Documents\Projects\hello-prisma\node_modules\prisma\query_engine-windows.dll.node'
npm ERR!  [OperationalError: EPERM: operation not permitted, unlink 'C:\Users\mbelletti\Documents\Projects\hello-prisma\node_modules\prisma\query_engine-windows.dll.node'] {
npm ERR!   cause: [Error: EPERM: operation not permitted, unlink 'C:\Users\mbelletti\Documents\Projects\hello-prisma\node_modules\prisma\query_engine-windows.dll.node'] {
npm ERR!     errno: -4048,
npm ERR!     code: 'EPERM',
npm ERR!     syscall: 'unlink',
npm ERR!     path: 'C:\\Users\\mbelletti\\Documents\\Projects\\hello-prisma\\node_modules\\prisma\\query_engine-windows.dll.node'
npm ERR!   },
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path: 'C:\\Users\\mbelletti\\Documents\\Projects\\hello-prisma\\node_modules\\prisma\\query_engine-windows.dll.node',
npm ERR!   parent: 'hello-prisma'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\mbelletti\AppData\Roaming\npm-cache\_logs\2021-09-09T08_05_23_557Z-debug.log
Error: Command failed with exit code 4294963248: npm install -D prisma@3.0.1
The batch file cannot be found.

The log file is the following: 2021-09-09T08_05_23_557Z-debug.log

After this, the node_modules.bin directory no longer has the prisma executable, and the node_modules/prisma folder only contains the file that npm wasn’t able to remove (query_engine-windows.dll.node).

Expected behavior

The script finishes correctly.

Prisma information

All the prisma configurations are the ones taken from the guide.

Environment & setup

  • OS: Windows 10
  • Database: PostgreSQL 13
  • Node.js version: 14.17.1 (using nvm)

Prisma Version

Environment variables loaded from .env
prisma                  : 3.0.1
@prisma/client          : Not found
Current platform        : windows
Query Engine (Node-API) : libquery-engine 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : 2452cc6313d52b8b9a96999ac0e974d0aedf88db
Studio                  : 0.423.0

(I had to relaunch npm install to get prisma back)

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 27
  • Comments: 110 (22 by maintainers)

Commits related to this issue

Most upvoted comments

Can confirm, just had the same error. Tried installing @prisma/client manually, it seems to help. So here is a possible workaround until the problem is fixed.

  1. Delete node_modules
  2. Run npm install
  3. Run npm install @prisma/client
  4. Run npx prisma generate / npm prisma migrate dev

I go this problem, and I noticed that .dll file were running due to my current terminal was running “npm dev run” I stopped the run and then the command was working nicely again. TRY STOPPING ACTIVE “npm run dev” or “npm start”

I dont know if anyone is having this issue anymore, but what helped me in my case is that first I stopped the server, then ran npx commands and it worked perfectly fine.

stop your npm server before running prisma generate

No need to uninstall node or prisma you just need stop the dev server

Just had this one, I found that the problem was that there was a nodejs instance still running that had imported prisma. Resolved by closing node. Recommend this be closed with a hotfix to better catch and label this error.

if you are working with nextjs stop the server and then run npx prisma generate this worked for me 😃

I think prisma is trying to delete the file “query_engine-windows.dll.node” while at the same time the node.js environment is using it. So the easiest solution I found is to stop the server you are using and run the command that was previously causing this error.

We tried reinstalling node js. That worked for us.

Try to install prisma client with: yarn add @prisma/client later try again with: yarn prisma migrate dev

Hello, updating my npm to the latest solve this error for me.

"In my situation this helped:

Before proceeding to execute these commands close all VS Code instances.

clean cache with

npm cache clean --force install the latest version of npm globally as admin:

npm install -g npm@latest --force clean cache with

npm cache clean --force Try to install your component once again.

I hope this fix your issue. If not, you may temporarily disable your antivirus program and try again."

source : https://stackoverflow.com/questions/39293636/npm-err-error-eperm-operation-not-permitted-rename

(This seems to happen on the in-the-background npm install @prisma/client and then corrupts the local prisma installation in the project, causing it to use an instant one via npx. I can reset by deleting node_modules, then npm install again - but on the next generate that tries to install @prisma/client in the background the same happens again.)

I’ve tried right now by removing the node_modules directory, re-installing the packages with npm install and re-running npx prisma migrate dev --name init, and got the same result:

Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "testprisma", schema "public" at "localhost:5432"

Already in sync, no schema change or pending migration was found.

Running generate... (Use --skip-generate to skip the generators)
npm WARN hello-prisma@1.0.0 No description
npm WARN hello-prisma@1.0.0 No repository field.

npm ERR! code EPERM
npm ERR! syscall unlink
npm ERR! path C:\Users\mbelletti\Documents\Projects\hello-prisma\node_modules\prisma\query_engine-windows.dll.node
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Users\mbelletti\Documents\Projects\hello-prisma\node_modules\prisma\query_engine-windows.dll.node'
npm ERR!  [OperationalError: EPERM: operation not permitted, unlink 'C:\Users\mbelletti\Documents\Projects\hello-prisma\node_modules\prisma\query_engine-windows.dll.node'] {
npm ERR!   cause: [Error: EPERM: operation not permitted, unlink 'C:\Users\mbelletti\Documents\Projects\hello-prisma\node_modules\prisma\query_engine-windows.dll.node'] {
npm ERR!     errno: -4048,
npm ERR!     code: 'EPERM',
npm ERR!     syscall: 'unlink',
npm ERR!     path: 'C:\\Users\\mbelletti\\Documents\\Projects\\hello-prisma\\node_modules\\prisma\\query_engine-windows.dll.node'
npm ERR!   },
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path: 'C:\\Users\\mbelletti\\Documents\\Projects\\hello-prisma\\node_modules\\prisma\\query_engine-windows.dll.node',
npm ERR!   parent: 'hello-prisma'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\mbelletti\AppData\Roaming\npm-cache\_logs\2021-09-10T07_27_58_812Z-debug.log
Error: Command failed with exit code 4294963248: npm install -D prisma@3.0.1
The batch file cannot be found.

The script tries to install @prisma/client and prisma if they doesn’t exists on your package.json file.

This is interesting, because prisma is already present in my package.json, but from what I see the script is trying to re-install prisma too (I guess so because the package getting disrupted is prisma itself). Could be a version problem?

Can you consistently reproduce this on your machine? Yes, on this machine it happens consistently, and yesterday evening I had the same problem on another machine (but I should check it today, I tried just once).

As an additional information, after the script breaks, the node_modules/prisma directory only contains query_engine-windows.dll.node. Could it be that the file is opened for some reason while the install script is running, and because of this it cannot be removed?

Stopping the dev server has worked for me.

If you’re using typescript try this ctrl+p Write this >TypeScript: Restart TS Server That’s all

(Remember stop server before running npx prisma generate)

Stopping the dev server worked for me too, but is there really no way to circumvent this? It’s an annoying thing to do.

i was running prisma studio in background kill your all open terminals and then try

The problem with this can be if you try building projects etc npm run build, and you started your Prisma, etc npx Prisma studio. The project throws this error because it cannot build a project if Prisma is running.

all the above solutions didn’t work for me, so, I searched for a hanging NodeJS process in my task manager, I found a process and killed it. and then, it is resolved.

Can confirm, just had the same error. Tried installing @prisma/client manually, it seems to help. So here is a possible workaround until the problem is fixed.

  1. Delete node_modules
  2. Run npm install
  3. Run npm install @prisma/client
  4. Run npx prisma generate / npm prisma migrate dev

I have error : “EPERM: operation not permitted, unlink 'C:\Users\ADMIN\Dfantasy\dFantasy-BE\node_modules@prisma\engines\schema-engine-windows.exe”, i tried to delete node_modules and manually reinstall prisma and @prisma/client but not work. Help me pls

You have to stop the server and then run npx prisma generate.

I go this problem, and I noticed that .dll file were running due to my current terminal was running “npm dev run” I stopped the run and then the command was working nicely again. TRY STOPPING ACTIVE “npm run dev” or “npm start”

Yeah stopping the dev server worked for me

You app can not run localy, you should stop the localserver.

Must stop server before running command.

Попробуйте остановить runtime приложение, если оно у вас запущено в данный момент, после остановки приложения, yarn prisma generate, если не поможет, то удалите папку node_modules -> yarn install -> yarn prisma generate

Edited by Prisma to add a transalation:

Try stopping the runtime application if you have it running at the moment, after stopping the application, yarn prisma generate, if that doesn’t help, then delete the folder node_modules -> yarn install -> yarn prisma generate

I dont know if anyone is having this issue anymore, but what helped me in my case is that first I stopped the server, then ran npx commands and it worked perfectly fine.

As simple as that, thanks

May help some, if your application is running while trying to migrate then prisma can’t unlink. If that’s the case just kill your node process and try again. I’ve done many times and forgotten that I still have my server running.

Same Issue here, it happens any time i migrate or generate. But when i stop my server and then run migrate or generate, it works fine.!

As @pfried mentioned, this only happened to me while I was running prisma studio in a background process. I stopped prisma studio and installed the dependency I needed and it worked normally. I don’t know why this happens but it would be great if they fixed it

@Jolg42 I do not think this is an error, because if you have a file in use by another process (the node dll) this is just the normal behaviour.

Just wanted to leave the comment because it could be helpful to others if they have the same issue

The fix provided by @NordicBeaver works perfectly and can bypass the issue.

Just to confirm, with that you mean a manual npm install @prisma/client before you first run npx prisma generate, correct?

Correct. Installing the client manually bypasses the issue.

Stop the dev server and run the npx prisma migrate dev command. It should work

I want to note that I accidentially ran into the same issue while prisma studio was running in the background

Current plan:

  • Don’t install the Prisma CLI when it is already present in package.json. This fixes the issue with npm 6.
  • Yarn still removes the DLL library in Prisma CLI even when @prisma/client (or any other unrelated package) is installed. If we detect that @prisma/client is missing and the project is using Yarn, prisma generate will abort and ask the user to install @prisma/client manually, since that’s the only safe option with Yarn.

Try to install prisma client with: yarn add @prisma/client later try again with: yarn prisma migrate dev

This solved my problema. Thanks!

Notice that if I had my backend server running, I constantly got this error. Once I stop the server, the error gone. My hunch is that the running server prevents deleting query_engine-windows.dll.node

If you are running nextjs server. Close the server and try running the command again.

$ npx prisma generate

yepp just kill the terminal, run prisma generate and npm run dev

For IISNode:-

  1. stop site from application pool
  2. run command prisma generate
  3. now start application pool

This works for me.

Can confirm, just had the same error. Tried installing @prisma/client manually, it seems to help. So here is a possible workaround until the problem is fixed.

  1. Delete node_modules
  2. Run npm install
  3. Run npm install @prisma/client
  4. Run npx prisma generate / npm prisma migrate dev

I have error : “EPERM: operation not permitted, unlink 'C:\Users\ADMIN\Dfantasy\dFantasy-BE\node_modules@prisma\engines\schema-engine-windows.exe”, i tried to delete node_modules and manually reinstall prisma and @prisma/client but not work. Help me pls

Just remove node modules folder.

Can confirm, just had the same error. Tried installing @prisma/client manually, it seems to help. So here is a possible workaround until the problem is fixed.

  1. Delete node_modules
  2. Run npm install
  3. Run npm install @prisma/client
  4. Run npx prisma generate / npm prisma migrate dev

This has just worked for me. Thanks

I had the same issues when trying to install a library (yarn add node-cron)… I tried @NordicBeaver solution (https://github.com/prisma/prisma/issues/9184#issuecomment-917396506) but just went to step 3 (yarn add @prisma/client). But I got the same result. Then I realized I had my server running so after I stoped it everything went to normal

@danielaliendo did you install the same version of Node.js or a newer one?

For the context: whether this issue is reproducible depends on the package manager. Latest versions of npm (such as bundled with Node.js 16 or 17) don’t try removing the library in the first place, thus circumventing this issue, but Yarn and npm 6 do.

Can you shared your node and npm version and how you installed it? I do not really think this is anything wrong with Prisma itself, but just a weird combination of different things in the setup leading to some broken behavior.

Sure. I was losing my mind over this, so I even reinstalled node. The versions are node: v14.17.6, npm: 6.14.15 on Windows 10.0.19043. I can get the error simply by creating empy folder, running npm init and npm install prisma, then adding a simple model and running npx prisma generate.

Btw, I just tried doing the same with the older prisma version (2.20.3) and I didn’t get the error.

Try closing any development servers you have that uses the prisma client and then try running the command again. That’s how I got mine to work.

While deleting the node_modules folder, I found that query_engine-windows.dll.node is open in node, and closing the dev server and prisma studio might also be a fix, instead of removing the node_modules folder

Stop the dev server and run the npx prisma migrate dev command. It should work

This Worked Thanks!!🤝

Stopping the dev server has worked for me.

It work for me right now

This usually happens because you are trying to do this and the development mode is working Turn off development mode and try again. I think this will solve the problem

i received this error when tried to generate when the code still running on it

Can confirm, just had the same error. Tried installing @prisma/client manually, it seems to help. So here is a possible workaround until the problem is fixed.

  1. Delete node_modules
  2. Run npm install
  3. Run npm install @prisma/client
  4. Run npx prisma generate / npm prisma migrate dev

This works for me. Thanks

Can confirm, just had the same error. Tried installing @prisma/client manually, it seems to help. So here is a possible workaround until the problem is fixed.

  1. Delete node_modules
  2. Run npm install
  3. Run npm install @prisma/client
  4. Run npx prisma generate / npm prisma migrate dev

Thanks, it work for me !

@Schmell

after updating to 5.0 this has become a nightmare to deal with

What version did you upgrade from? I don’t remember any changes in Prisma 5 that could influence this in any way, but I just remembered one change from Prisma 4.15 that might have made this happen more often (https://github.com/prisma/prisma/pull/19225).

getting the same error- I cannot prisma:generate if the client is already being used in an app which is running

Thank you both @StrahinjaWebDev & @ishaqyusuf for reporting this in comments here, I randomly found them.

Could you actually create a new bug issue, so we can look at it again with fresh eyes on a fresh version of Prisma?

Note: creating a new bug issue (and mentioning this one) is the best way to have us look at it, comments in closed issues are very likely to be unseen.

Can confirm, just had the same error. Tried installing @prisma/client manually, it seems to help. So here is a possible workaround until the problem is fixed.

  1. Delete node_modules
  2. Run npm install
  3. Run npm install @prisma/client
  4. Run npx prisma generate / npm prisma migrate dev

Shockingly this worked for me. To be clear I had two distinct, yet connected errors:

  1. even as an admin, I wasn’t able to delete a file generated by the prisma client within my node_modules folder
  2. after painfully figuring out how to delete that folder, and doing an npm i, “npx prisma generate” failed due to a permissions issue.

Only after deleting the file, node_modules folder, re-installing from my package.json (which already includes prisma and @prisma/client), and then “npm i @prisma/client” explicitly after my npm -i, was I able to get “npx prisma generate” to work.

To be clear the offical prisma docs state the following: “Note also that prisma generate is automatically invoked when you’re installing the @prisma/client npm package. So, when you’re initially setting up Prisma Client, you can typically save the third step from the list above.”

The issue seems to come when you have either a remix instance or prisma studio running. Make sure neither is running before you run npx primsa migrate dev or npx primsa generate.

I stumbled across this just now. I do not have a Prisma studio running. I have tried with and without my nest.js app running in the background.

Deleting node_modules magically fixed it for me. I’ll come back if I experience this again.

Internal note:

This seems to be related to the Node-API library for Windows query_engine-windows.dll.node. When using the escape hatch to return to the binary engine,

PRISMA_CLI_QUERY_ENGINE_TYPE=binary
PRISMA_CLIENT_ENGINE_TYPE=binary

(for example in your .env file), the error does not occur like it does described above. Instead you get this one:

C:\Users\Jan\Documents\throwaway\9184>npx prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma

> prisma@3.0.2 preinstall C:\Users\Jan\Documents\throwaway\9184\node_modules\prisma
> node scripts/preinstall-entry.js


> prisma@3.0.2 install C:\Users\Jan\Documents\throwaway\9184\node_modules\prisma
> node scripts/install-entry.js

npm notice save prisma is being moved from dependencies to devDependencies
npm WARN 9184@1.0.0 No description
npm WARN 9184@1.0.0 No repository field.

+ prisma@3.0.2
updated 1 package and audited 2 packages in 1.474s
found 0 vulnerabilities

npm WARN 9184@1.0.0 No description
npm WARN 9184@1.0.0 No repository field.

npm ERR! code ENOENT
npm ERR! syscall rename
npm ERR! path C:\Users\Jan\Documents\throwaway\9184\node_modules\@prisma\client
npm ERR! dest C:\Users\Jan\Documents\throwaway\9184\node_modules\@prisma\.client.DELETE
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Jan\Documents\throwaway\9184\node_modules\@prisma\client' -> 'C:\Users\Jan\Documents\throwaway\9184\node_modules\@prisma\.client.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Jan\AppData\Roaming\npm-cache\_logs\2021-09-20T19_03_16_214Z-debug.log
Error: Command failed with exit code 4294963238: npm install @prisma/client@3.0.2

This points to different behavior regarding the Node-API library Query Engine, probably still being used by the CLI in some way when this npm install -D prisma is executed for some reason.

Could it be that the file is opened for some reason while the install script is running, and because of this it cannot be removed?

Might be possible. Did you try completely removing node_modules once and trying to reproduce this again?