Xiaohua Cao
Xiaohua Cao

Reputation: 889

Error: EBUSY: resource busy or locked, rmdir

The error occurs after following steps in windows:

  1. Open one terminal: npm run start:dev
  2. Open another terminal: ng build --watch

However, it works in Mac by using the above commands. Part of the package.json configuration are:

"scripts": {
"ng": "ng",
"start:dev:prod": "ng build --prod && cd dist/ && node static/server.js",
"start": "node static/server.js",
"build:prod": "ng build --prod",
"test": "ng test --code-coverage",
"lint": "ng lint",
"e2e": "ng e2e",
"start:dev": "npm run build & cd dist/ & SET APP_ENV=dev & node static/server.js",
"build": "ng build"
},

Error log:

Error: EBUSY: resource busy or locked, rmdir 'C:\AngularProject\dist'
Error: EBUSY: resource busy or locked, rmdir 'C:\Spring-Intern-Projects\wdpr-accounting-reference-client\dist'
at Object.rmdirSync (fs.js:701:3)

Upvotes: 78

Views: 250882

Answers (21)

Ahsan Alamgir
Ahsan Alamgir

Reputation: 31

In angular, I made some code changes which caused angular cache issue. So, I had to close vscode and forcefully delete .angular folder.

rm -rf .angular

After restarting the resources, it worked fine. Thanks.

Upvotes: 0

Lenzman
Lenzman

Reputation: 1400

For VsCode users:

Check if the directory/folder you are trying to delete is opened in the terminal(s). There might be multiple terminal instances, so check if you have any.

Changing the directory opened in the terminal or killing that terminal instance will solve the issue.

If none of these works, close the vscode and try again. Thanks @Vugar Abdullayev

Upvotes: 22

LongDev
LongDev

Reputation: 223

with nextjs, you can try delete existing build folder

Upvotes: 0

janat08
janat08

Reputation: 1777

I installed WSL, and connected to it with VSC. None of the solutions above have worked.

Upvotes: 0

sajith thiwanka
sajith thiwanka

Reputation: 1

I solved my problem by granting the permissions to the relevant locked folder.

Upvotes: -2

CSSBurner
CSSBurner

Reputation: 1991

Using Jest, and after upgrading to Angular 13, I started to get this error message.

I found out it was due to failed unit tests that still were using (incorrectly) Jasmine syntax. For example:

spyOn() // instead of jest.spyOn()
expect().and.returnValue(X) // instead of expect().mockReturnValue(X)

Once I updated my syntax to be "pure Jest" instead of Jasmine/Jest mixtures, these errors were resolved, and the EBUSY error was no longer thrown.

Upvotes: 0

Shadab Ahmed
Shadab Ahmed

Reputation: 576

I tried deleting node modules and re-installing them but it didn't work. The issue in my case was because of a wrongly imported dependency by VSCode, I fixed the issue by removing the last imports I added to my code.

Upvotes: -1

Arun Kumar
Arun Kumar

Reputation: 209

Restarting the system fixed the issue for me.

Upvotes: 0

user16136444
user16136444

Reputation:

It also occurs to me when I want to delete my data.db file when running and playing around with a simple python application that I made (app.py) to test the connection with my sqlite3 db. When I want to delete the .db file, my app.py is still running in the terminal, and the error pops up.

So, what I do is I kill/stop the terminal that runs the app.py. After stopping the running terminal, I can delete the .db file successfully.

*This is on windows PC.

Upvotes: -1

Siphamandla Ngwenya
Siphamandla Ngwenya

Reputation: 3064

It usually happens when the folder is opened in the terminal, after stopping the terminal i was able to delete the folder.

Upvotes: -2

Eric
Eric

Reputation: 85

Just close the terminal and open it again

Upvotes: -2

Nicholas Mberev
Nicholas Mberev

Reputation: 1841

If all the above solutions did not work AND you are using windows PC like in my case, the easiest thing to do is:

  1. Press windows key plus R on your keyboard to open the run command box and type this

    resmon.exe

  2. click OK to open resource monitor

  3. In the monitor, navigate to CPU tab

  4. Under Associated Handles in the search box, copy the path to the file or folder in question and paste it in there

  5. Click on the search icon

  6. You should be able to see all the programs using the file or folder

  7. right-click each and end-process

enter image description here

Now, continue what you were trying to do on the file or folder. In my case I was having problems using react-create-app via npm. More information here #117908

I just hope it helps someone.

Upvotes: 127

mahmood
mahmood

Reputation: 399

In my case android studio and VSCode was open. Closing android studio helped.

Upvotes: 0

Zulfikar Ahmad
Zulfikar Ahmad

Reputation: 504

Sometimes (in other case) its just a network problem, what im doing just using VPN, and its work.

Upvotes: -1

Balaji
Balaji

Reputation: 10877

This is happend by overwrite some npm so it locked your source

solutions(what i did npm cache clean is also not working then i deleted package-lock started working)

  1. simply delete package-lock

  2. clean cache.

    npm cache clean

    also clear cache(optional)

  3. npm install --cache

Upvotes: 9

Alex Sorkin
Alex Sorkin

Reputation: 101

I had a same problem and found the reason - the project is inside dropbox folder that synchronize and locke the node_modules folder. I closed dropbox and it worked.

Upvotes: 4

Pedroxam
Pedroxam

Reputation: 27

node_modules folder contents can make bad sectors on the drives, using defrag and optimiziton software for this drives can reduce problems like this.

Upvotes: -4

ufukcam
ufukcam

Reputation: 83

You can delete following folder, then you can try again. Worked for me.

C:\Users\{username}\AppData\Local\Temp\npm-xxxxxxxxxx\

Upvotes: 1

Balaji Dharma
Balaji Dharma

Reputation: 1425

This issue due to cache, run the below command in terminal

npm cache verify

Upvotes: 24

JMeter Dude
JMeter Dude

Reputation: 329

I was able to solve my killing the npm and Java processes. I was having issue running my Cordova run android, so killing npm and java processes helped me solve the issue.

Upvotes: 3

JoeMoe1984
JoeMoe1984

Reputation: 2032

The main reason you are seeing this error is due to a program putting a lock on the folder for whatever reason. Testing the command while closing programs one at a time can help resolve the issue and let you know which program is the culprit.

One issue people were having was with anti-malware on windows. You can read through this thread here:

https://github.com/npm/npm/issues/13461

In case link stops working here was the most upvoted comment:

In Windows 10 64-bit OS, I have resolved this issue by uninstalling Anti-Malware software.

Another way you can trigger this error is if you are running an npm run [command] while cd'd into the directory that its altering. This happened to me where I closed every program and it didn't work, but realized I was inside the dist folder which needed to be removed and rebuilt. This triggered the Error: EBUSY: resource busy or locked, rmdir error in PowerShell and can be reproduced every time.

Upvotes: 10

Related Questions