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
- Follow the Getting started prisma guide up to and included the “npx prisma migrate dev --name init” command.
- 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)
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.node_modules
npm install
npm install @prisma/client
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.
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 localprisma
installation in the project, causing it to use an instant one vianpx
. I can reset by deletingnode_modules
, thennpm install
again - but on the nextgenerate
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-runningnpx prisma migrate dev --name init
, and got the same result: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?
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.
You have to stop the server and then run
npx prisma generate
.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:
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
Correct. Installing the client manually bypasses the issue.
Stop the dev server and run the
npx prisma migrate dev
command. It should workI want to note that I accidentially ran into the same issue while prisma studio was running in the background
Current plan:
package.json
. This fixes the issue with npm 6.@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.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:-
This works for me.
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.
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.
Sure. I was losing my mind over this, so I even reinstalled node. The versions are
node: v14.17.6
,npm: 6.14.15
onWindows 10.0.19043
. I can get the error simply by creating empy folder, runningnpm init
andnpm install prisma
, then adding a simple model and runningnpx 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 thatquery_engine-windows.dll.node
is open in node, and closing the dev server and prisma studio might also be a fix, instead of removing thenode_modules
folderThis Worked Thanks!!🤝
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
This works for me. Thanks
Thanks, it work for me !
@Schmell
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 runningThank 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.
Shockingly this worked for me. To be clear I had two distinct, yet connected errors:
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
ornpx 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,(for example in your
.env
file), the error does not occur like it does described above. Instead you get this one: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.Might be possible. Did you try completely removing
node_modules
once and trying to reproduce this again?