Reputation: 889
The error occurs after following steps in windows:
npm run start:dev
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
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
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
Reputation: 1777
I installed WSL, and connected to it with VSC. None of the solutions above have worked.
Upvotes: 0
Reputation: 1
I solved my problem by granting the permissions to the relevant locked folder.
Upvotes: -2
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
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
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
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
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:
Press windows key plus R on your keyboard to open the run command box and type this
resmon.exe
click OK to open resource monitor
In the monitor, navigate to CPU tab
Under Associated Handles in the search box, copy the path to the file or folder in question and paste it in there
Click on the search icon
You should be able to see all the programs using the file or folder
right-click each and end-process
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
Reputation: 399
In my case android studio and VSCode was open. Closing android studio helped.
Upvotes: 0
Reputation: 504
Sometimes (in other case) its just a network problem, what im doing just using VPN, and its work.
Upvotes: -1
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)
simply delete package-lock
clean cache.
npm cache clean
also clear cache(optional)
npm install --cache
Upvotes: 9
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
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
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
Reputation: 1425
This issue due to cache, run the below command in terminal
npm cache verify
Upvotes: 24
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
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