Azure / azure-iot-hub-node

Azure IoT Hub Data Plane Node SDK
MIT License
2 stars 8 forks source link

[BUG] v1.16.3 Breaking Dependency Change #23

Closed ghost closed 1 year ago

ghost commented 1 year ago

Context

With the most recent patch version 1.16.3, there appears to be a difference in the required dependencies (and compiled output) compared to the previous version 1.16.2 that causes module resolution issi

Discoveries

Dependencies Variation

See below differences in the package.json.

v1.16.2

  "dependencies": {
    "@azure/core-auth": "^1.4.0",
    "@azure/identity": "^2.0.0",
    "@azure/ms-rest-js": "^2.0.5",
    "async": "^3.2.3",
    "azure-iot-amqp-base": "2.5.2",
    "azure-iot-common": "1.13.2",
    "azure-iot-http-base": "1.12.2",
    "debug": "^4.3.1",
    "lodash": "^4.17.21",
    "machina": "^4.0.2",
    "rhea": "^1.0.15"
  }

v1.16.3

  "dependencies": {
    "@azure/core-auth": "^1.4.0",
    "@azure/identity": "^2.0.0",
    "@azure/ms-rest-js": "^2.0.5",
    "async": "^3.2.3",
    "debug": "^4.3.1",
    "getos": "^3.2.1",
    "lodash": "^4.17.21",
    "machina": "^4.0.2",
    "rhea": "^1.0.15"
  }

In v1.16.3, there are 3 additional folders in the dist output:

image

Requiring lodash.merge (called from dist/common-amqp/amqp.js) fails due to missing the azure-iot-amqp-base dependency which had been included with this lib.

Error: Cannot find module 'lodash.merge'
Require stack:
- /usr/src/app/node_modules/azure-iothub/dist/common-amqp/amqp.js
- /usr/src/app/node_modules/azure-iothub/dist/amqp.js
- /usr/src/app/node_modules/azure-iothub/dist/client.js
- /usr/src/app/node_modules/azure-iothub/iothub.js
- /usr/src/app/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
    at Function.Module._load (node:internal/modules/cjs/loader:871:27)
    at Module.require (node:internal/modules/cjs/loader:1098:19)
    at require (node:internal/modules/cjs/helpers:108:18)
    at Object.<anonymous> (/usr/src/app/node_modules/azure-iothub/dist/common-amqp/amqp.js:16:15)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Module.require (node:internal/modules/cjs/loader:1098:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/src/app/node_modules/azure-iothub/dist/common-amqp/amqp.js',
    '/usr/src/app/node_modules/azure-iothub/dist/amqp.js',
    '/usr/src/app/node_modules/azure-iothub/dist/client.js',
    '/usr/src/app/node_modules/azure-iothub/iothub.js',
  ]

Resolution

I was able to revert to v1.16.2 which does not experience this issue. My recommendation is to replace any lodash direct npm package calls (e.g. lodash.merge) with either named imports or submodules of the main lodash package (e.g. lodash/merge).

hgenr commented 1 year ago

We ran into the same issue and reverted to v1.16.2. Would be nice to have a release for the fix. Thank you for your work!