Posts: 1
Joined: Sat Mar 16, 2019 9:24 pm

onoff : fs.existsSync is not a function

Sat Mar 16, 2019 9:37 pm

I am working on a Pi project with onoff, Node and Vue. Have been trying to implement a simple LED switch using this code :

Code: Select all

etOutput : function(){
var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO
var LED = new Gpio(4, 'out'); //use GPIO pin 4, and specify that it is output
var blinkInterval = setInterval(blinkLED, 250); //run the blinkLED function every 250ms

function blinkLED() { //function to start blinking
  if (LED.readSync() === 0) { //check the pin state, if the state is 0 (or off)
    LED.writeSync(1); //set pin state to 1 (turn LED on)
  } else {
    LED.writeSync(0); //set pin state to 0 (turn LED off)

function endBlink() { //function to stop blinking
  clearInterval(blinkInterval); // Stop blink intervals
  LED.writeSync(0); // Turn LED off
  LED.unexport(); // Unexport GPIO to free resources

setTimeout(endBlink, 5000); //stop blinking after 5 seconds

However, this gives me an error :

Code: Select all

 ypeError: fs.existsSync is not a function
    at new Gpio (webpack-internal:///./node_modules/onoff/onoff.js:94)
    at VueComponent.setOutput (webpack-internal:///./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/HelloWorld.vue:88)
    at invokeWithErrorHandling (webpack-internal:///./node_modules/vue/dist/vue.esm.js:1862) 

Pi is updated and LED works just fine using a python script. I also tried other npm libraries like pigpio and rpi-gpio but received similar / same errors. Am I missing something?


Posts: 1557
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: onoff : fs.existsSync is not a function

Sat Mar 16, 2019 11:53 pm

The fs.existsSync has been / is being deprecated going by ... tssyncpath. I cannot tell the date of the docs as the ‘about’ does not exist...

You either have an old code block (that calls it) or something that’s too new (has removed it).

Not that that helps you fix you problem :cry:
Need Pi spray - these things are breeding in my house...

Return to “Advanced users”