Getting Error EBUSY: resource busy or locked
Asked Answered
S

10

12

Trying to run a Nodejs app to test Raspberry 3 B + Gpio Onoff Module but when i am trying to run the app getting this Error

fs.js:114
throw err;

Error: EBUSY: resource busy or locked, write
at Object.writeSync (fs.js:568:3)
at Object.writeFileSync (fs.js:1199:26)
at new Gpio (/home/pi/Desktop/pitesting/node_modules/onoff/onoff.js:96:10)
at Object.<anonymous> (/home/pi/Desktop/pitesting/blink.js:3:7)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)

Here is my App Code

var onoff = require('onoff');
var Gpio = onoff.Gpio,
  led = new Gpio(4, 'out'),
  interval;
interval = setInterval(function () {
  var value = (led.readSync() + 1) % 2;
  led.write(value, function () {
    console.log("Changed LED state to: " + value);
  });
}, 2000);
process.on('SIGINT', function () {
  clearInterval(interval);
  led.writeSync(0);
  led.unexport();
  console.log('Bye, bye!');
  process.exit();
});

Already Tried Fixes by updating and upgrading apt and reinstalling node modules.

Please Help me to resolve this issue.

Sunburst answered 9/3, 2019 at 19:43 Comment(0)
L
21

There are many answers on GitHub regarding this issue.

  • Some says npm cache clean this command executing on terminal solved the problem.

  • Others recommend to delete the entire directory your app is the folder in and re-install the packages and then try running the program.

  • Some also says that It is caused by the anti-malware software and recommend to disable it while running the program.

GitHub issue link: https://github.com/npm/npm/issues/13461

If it doesn't solve the issue, just change the GPIO pin to let's say 23 in coding and don't forget to physically replace LED from 4 to 23 too.

Leggy answered 9/3, 2019 at 19:43 Comment(2)
@SyedMuhammadDanishIqbal probably you Port 4 is busy. Try changing the GPIO pin. Let's say 21 or 23 or any other you likeTithe
@SyedMuhammadDanishIqbal don't forget to change LED pin physically tooTithe
P
7

This problem can occur when you try to write to a file that is open in an editor

Polity answered 23/4, 2021 at 10:21 Comment(1)
This worked for me. I had the folder I was trying to delete open in my terminal.Carlenacarlene
Q
3
var onoff = require('onoff');
var Gpio = onoff.Gpio,
    led = new Gpio(4, 'out'),
    interval;
interval = setInterval(function () {
    var value = (led.readSync() + 1) % 2;
    led.write(value, function () {
        console.log("Changed LED state to: " + value);
    });
}, 2000);
process.on('SIGINT', function () {
    clearInterval(interval);
    led.writeSync(0);
    led.unexport();
    console.log('Bye, bye!');
    process.exit();
});
Queridas answered 10/3, 2019 at 16:45 Comment(0)
G
1

Simply close everything , including your visual studio or any app you are using and start ng serve or ng build again , you will get your server running

Ghyll answered 3/11, 2020 at 16:25 Comment(0)
N
0

Some says npm cache clean this command is not properly work.

we try uninstall nodejs and reinstall nodejs

after properly work

Neodymium answered 2/3, 2020 at 12:20 Comment(0)
M
0

Find the packager-info.json file inside the .expo folder and delete it. Now restart it by expo start command.

Memorabilia answered 19/7, 2020 at 7:36 Comment(0)
F
0

If you are on windows.

Try running your bash window as Administrator.

For example, in my case, I was using git bash.

Search on windows "Gitbash" (or any other command-line window) -> Right-click -> Run as Administrator. Worked for me.

Fusain answered 13/8, 2020 at 16:18 Comment(0)
H
0

I know this is barley advice since its so obvious but I spent over an hour on this then restarted my computer, problem fixed!

just a reminder the most obvious solutions are sometimes the right solutions.

All the other solutions posted about this problem didnt work for me. Maybe because my problem was a log file was being locked which prevented me from using npm at all. The log file didn't even show up in the directory it was supposed to be in.

Hashim answered 14/9, 2020 at 15:31 Comment(0)
D
0

Another cause for the issue may be that your npm package includes a package that does not exist. In my case I have a private repository that is included in my package.json - but it was pointing at a git tag/version that did not exist. Fixing this error and running

npm install

(ignoring any errors) fixed it for me. To be save I ran

npm ci

afterwards, but that may be unnecessary.

Drawbar answered 2/3, 2022 at 10:50 Comment(0)
M
0

In my case the error was:

Error: EBUSY: resource busy or locked, unlink '...\node_modules\electron\dist\v8_context_snapshot.bin'

All I had to do was Kill electron processes from task manager before running the app again.

Marcelmarcela answered 27/1, 2024 at 18:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.