2016-09-22 17 views
7

Tôi đang sử dụng Microsoft Cognitive Services api cho nútjs. Tôi đã mã sauLoạiError: cognitiveServices.face không phải là hàm tạo

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

Tuy nhiên, khi tôi thực hiện đoạn mã này tôi nhận được lỗi sau

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 

Làm thế nào tôi có thể giải quyết lỗi này?

+0

Bạn có một yêu cầu tuyên bố ở trên cùng của mô-đun mà, phải không? Bạn có thể chỉnh sửa câu hỏi của mình để bao gồm tuyên bố đó không? Tương tự như vậy nó sẽ là tốt để xác minh rằng bạn đã cài đặt đúng api dịch vụ nhận thức cho mỗi bước Cài đặt và Bắt đầu tại https://github.com/joshbalfour/node-cognitive-services#installation. – ArthurDenture

+0

Có Tôi có điều đó và tôi đã cập nhật câu hỏi của mình. – 2619

+0

Xin chào, câu trả lời của tôi có phù hợp với bạn không? Tôi thấy rằng tiền thưởng vẫn còn mở ... – ArthurDenture

Trả lời

5

Dường như tài liệu cho mô-đun cognitive-services không chính xác: bạn cần gọi cognitiveServices.face(...) mà không cần new.

Nếu bạn nhìn vào https://github.com/joshbalfour/node-cognitive-services/blob/master/api/face.js, bạn có thể thấy rằng face được định nghĩa là hàm mũi tên, làm cho nó không phải là hàm tạo. Xem https://stackoverflow.com/a/37037600/483595 để biết chi tiết về lý do.

Edit: trông giống như vấn đề này đã được báo cáo ở đây: https://github.com/joshbalfour/node-cognitive-services/issues/2

+0

Lỗi này đã được sửa :) –

Các vấn đề liên quan