2016-11-17 14 views
-1

С NodeJS Я использую основную документацию, образец здесь: https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-node-node-getstartediothub.Device не является конструктором объекта. <anonymous>

Однако я получаю эту ошибку:

iothub.Device is not a constructor at Object. (/Users/luis.valencia/Projects/IoTSamples/NodeJSIoTHelloWorld /CreateDeviceIdentity.js:7:14) at Module._compile (module.js:541:32) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.runMain (module.js:575:10) at run (bootstrap_node.js:352:7) at startup (bootstrap_node.js:144:9) at bootstrap_node.js:467:3

Мой код выглядит следующим образом:

'use strict'; 
var iothub = require('azure-iothub'); 
var connectionString = 'HostName=xyz.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xyz='; 
var registry = iothub.Registry.fromConnectionString(connectionString); 
var deviceId = "helloworlddevice"; 

var device = new iothub.Device(null); 
device.deviceId = deviceId; 

registry.create(device, function(err, deviceInfo, res) { 
    if (err) 
    registry.get(device.deviceId, printDeviceInfo); 

    if (deviceInfo) 
    printDeviceInfo(err, deviceInfo, res) 
}); 

function printDeviceInfo(err, deviceInfo, res) { 
    if (deviceInfo) 
    console.log('Generated device key: ' + deviceInfo.authentication.SymmetricKey.primaryKey); 
} 
+0

позор на -1, без комментариев. –

ответ

0

Был ошибка в пакете npm, после сообщения его MS на github, он был исправлен, выпущен на ночь, поэтому я только что установил пакет снова, и проблема была решена.

 Смежные вопросы

  • Нет связанных вопросов^_^