2016-09-22 16 views
7

nodejsにMicrosoft Cognitive Services apiを使用しています。私はこのコード私は、次の取得エラーTypeError:cognitiveServices.faceがコンストラクタではありません

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 

がどのように私はこのエラーを解決することができます実行したとき、私は、コードが

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); 
     }); 

次がありますか?

+0

は、あなたは正しい、そのモジュールの上部にある文を必要としていますか?その声明を含めるためにあなたの質問を編集できますか?同様に、https://github.com/joshbalfour/node-cognitive-services#installationで、インストールとスタートアップの手順に従って認知サービスAPIを正しくインストールしたことを確認するとよいでしょう。 – ArthurDenture

+0

はい私はそれを持っており、私は質問を更新しました。 – 2619

+0

こんにちは、私の答えはあなたのために働いたのですか?私は賞金がまだ開いているのを見る... – ArthurDenture

答えて

5

cognitive-servicesモジュールのドキュメントが間違っているようです:なしでcognitiveServices.face(...)に電話する必要があります。

https://github.com/joshbalfour/node-cognitive-services/blob/master/api/face.jsを見ると、faceが矢印関数として定義されていることがわかります。これはコンストラクタではありません。その理由については、https://stackoverflow.com/a/37037600/483595を参照してください。

編集:問題のように見えますが、すでにここに報告されていますhttps://github.com/joshbalfour/node-cognitive-services/issues/2

+0

このエラーは修正されています:) –

関連する問題