TypeError: Class constructor Wia cannot be invoked without 'new'
TypeError: Class constructor Wia cannot be invoked without 'new'
这是我在 json 文件中的代码,每当我尝试 运行 它时,我都会收到此错误:
TypeError: Class 没有 'new' 就无法调用构造函数 Wia
在对象。 (/home/pi/wia-pi-camera/run-camera.js:3:25)
'use strict';
var wia = require('wia')('your-device-secret-key');
var fs = require('fs');
var RaspiCam = require("raspicam");
// Setup the camera
var camera = new RaspiCam({
mode: 'photo',
output: __dirname + '/photo.jpg',
encoding: 'jpg'
});
// Listen for the "start" event triggered when the start method has been successfully initiated
camera.on("start", function(){
console.log("Starting to take photo.");
});
// Listen for the "read" event triggered when each new photo/video is saved
camera.on("read", function(err, timestamp, filename){
console.log("New photo created.", timestamp, filename);
// Publish the photo to Wia
wia.events.publish({
name: 'photo',
file: fs.createReadStream(__dirname + '/' + filename)
});
});
// Take a photo
camera.start();
第二行似乎是错误发生的地方:var wia = require('wia')('my_device_secret_key');
有谁知道如何解决这个问题?
试试这样:
const Wia = require('wia');
var wia = new Wia('your-device-secret-key');
require('wia')
returns一个class,你需要用new
调用它来创建一个实例。
这是我在 json 文件中的代码,每当我尝试 运行 它时,我都会收到此错误: TypeError: Class 没有 'new' 就无法调用构造函数 Wia 在对象。 (/home/pi/wia-pi-camera/run-camera.js:3:25)
'use strict';
var wia = require('wia')('your-device-secret-key');
var fs = require('fs');
var RaspiCam = require("raspicam");
// Setup the camera
var camera = new RaspiCam({
mode: 'photo',
output: __dirname + '/photo.jpg',
encoding: 'jpg'
});
// Listen for the "start" event triggered when the start method has been successfully initiated
camera.on("start", function(){
console.log("Starting to take photo.");
});
// Listen for the "read" event triggered when each new photo/video is saved
camera.on("read", function(err, timestamp, filename){
console.log("New photo created.", timestamp, filename);
// Publish the photo to Wia
wia.events.publish({
name: 'photo',
file: fs.createReadStream(__dirname + '/' + filename)
});
});
// Take a photo
camera.start();
第二行似乎是错误发生的地方:var wia = require('wia')('my_device_secret_key');
有谁知道如何解决这个问题?
试试这样:
const Wia = require('wia');
var wia = new Wia('your-device-secret-key');
require('wia')
returns一个class,你需要用new
调用它来创建一个实例。