TypeError:cognitiveServices.face不是一个构造函数

我正在使用Microsoft Cognitive Services API for nodejs。 我有以下代码

const cognitiveServices = require('cognitive-services'); const face = new cognitiveServices.face({ API_KEY: yourApiKey }) const parameters = { returnFaceId: "true" returnFaceLandmarks: "false" }; const body = { "url": "URL of input image" }; face.detect({ parameters, body }) .then((response) => { console.log('Got response', response); }) .catch((err) => { console.error('Encountered error making request:', err); }); 

但是,当我执行此代码时,我得到以下错误

  const face = new cognitiveServices.face({ ^ TypeError: cognitiveServices.face is not a constructor at Object.<anonymous> (/Users/..../face.js:3:14) at Module._compile (module.js:556:32) at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.runMain (module.js:590:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3 

我怎样才能解决这个错误?

它看起来像cognitive-services模块的文档是不正确的:你需要调用cognitiveServices.face(...)没有new

如果你看一下https://github.com/joshbalfour/node-cognitive-services/blob/master/api/face.js ,你可以看到face被定义为一个箭头函数,这使得它不是一个构造函数。 请参阅https://stackoverflow.com/a/37037600/483595了解为什么这样的情况&#x3002;

编辑:看起来像这个问题已经在这里报道: https : //github.com/joshbalfour/node-cognitive-services/issues/2