【问题标题】:iothub.Device is not a constructor at Object.<anonymous>iothub.Device 不是 Object.<anonymous> 的构造函数
【发布时间】:2016-11-18 03:53:05
【问题描述】:

对于 NodeJS,我使用的是这里的基本示例文档: https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-node-node-getstarted

但是我得到了这个错误:

iothub.Device 不是 Object 的构造函数。 (/Users/luis.valencia/Projects/IoTSamples/NodeJSIoTHelloWorld /CreateDeviceIdentity.js:7:14) 在 Module._compile (module.js:541:32) 在 Object.Module._extensions..js (module.js:550:10) 在 Module.load (module.js:458:32) 在 tryModuleLoad (module.js:417:12) 在 Module.runMain 处的 Function.Module._load (module.js:409:3) (module.js:575:10) 在运行时 (bootstrap_node.js:352:7) 在启动时 (bootstrap_node.js:144:9) 在 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);
}

【问题讨论】:

  • 对-1感到羞耻,没有评论。

标签: javascript node.js azure azure-iot-hub azure-iot-sdk


【解决方案1】:

npm包有一个bug,在github上报告给MS后,修复了,一夜之间发布了,所以我又重新安装了包,问题解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 2021-09-28
    • 1970-01-01
    • 2023-02-06
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    相关资源
    最近更新 更多