Spark-tinker crashes: cannot read property 'message'

I am trying to control a Photon with spark-tinker in nodejs. I can turn the LED on with this code:

var Spark =require('spark');
Spark.include('tinker');
Spark.login({accessToken: process.env.SPARK_TOKEN });

var devicesPr = Spark.listDevices();

devicesPr.then(
    function(devices){

  	var callback = function(err, data) {
          if (err) {
            console.log('An error occurred while calling function:', err);
          } else {
            console.log('function called successfully:', data);
          }
        };

      console.log('Devices: ', devices);
      devices[5].tinker.digitalWrite('D7', 'HIGH', callback);

    },
    function(err) {
      console.log('List devices call failed: ', err);
    }
);

This code turns the LED on and then it crashes with the following error:

TypeError: Cannot read property 'message' of null
    at localCb (/home/ubuntu/project/call/node_modules/spark-tinker/lib/tinker.js:48:12)
    at Spark.emitAndCallback (/home/ubuntu/project/call/node_modules/spark/lib/spark.js:136:42)
    at null.<anonymous> (/home/ubuntu/project/call/node_modules/spark/lib/spark.js:154:10)
    at Request.self.callback (/home/ubuntu/project/call/node_modules/spark/node_modules/request/request.js:198:22)
    at Request.emit (events.js:98:17)
    at Request.<anonymous> (/home/ubuntu/project/call/node_modules/spark/node_modules/request/request.js:1063:14)
    at Request.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/home/ubuntu/project/call/node_modules/spark/node_modules/request/request.js:1009:12)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:943:16

Any idea?

Thanks
Roge

I fixed by changing tinker.js, instead of

if (err.message === 'Function not found') {

use

if (data.message === 'Function not found') {