Handling version incompatibility in npm dependencies

328 views Asked by At

Some context

Every time VS Code is released built on a new version of Node, the VS Code Arduino extension breaks until a new version is released.

Having cloned the Arduino extension git repo I uninstalled it as an extension and ran it in the debugger. This worked and now I have specific intel, if only I knew how to act on it. This is the message:

[Warn] no library available after trying files native_loader.js
undefined
Array[3]
0
"d:/vscode-arduino/out/node_modules/node-usb-native/lib/native/detector_darwin_7.1.11_x64.node"
1
"d:/vscode-arduino/out/node_modules/node-usb-native/lib/native/detector_Ubuntu14.04_7.1.11_x64.node"
2
"d:/vscode-arduino/out/node_modules/node-usb-native/lib/native/detector_win32_7.1.11_x64.node"
rejected promise not handled within 1 second: Error: The module '\\?\d:\vscode-arduino\out\node_modules\usb-detection\build\Release\detection.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 80. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
 extensionHostProcess.js
stack trace: Error: The module '\\?\d:\vscode-arduino\out\node_modules\usb-detection\build\Release\detection.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 80. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

The last of these files (the Windows x64 one) is indeed present on the expected path so "no library available" doesn't mean it can't find the file. This agrees with the end of the message which reports that no suitable version can be found.

The end of this message suggests npm rebuild or npm i so I tried those to no avail.

Rummaging in package.json revealed

  "scripts": {
    "vscode:prepublish": "gulp build --mode=production",
    "postinstall": "cd ./src/views && npm install && node ../../node_modules/node-usb-native/scripts/rebuild-serialport.js",
    "test": "gulp test"
  },
  "extensionDependencies": [
    "ms-vscode.cpptools"
  ],
  "devDependencies": {
    "@types/compare-versions": "^3.0.0",
    ...
    "webpack": "^4.44.1"
  },
  "dependencies": {
    ...
    "node-usb-native": "0.0.13",
    ...
  }

The dependency on node-usb-native is behind the latest (0.0.15). Changing this and running npm i triggers the post-install task to rebuild-serialport.js which appears to succeed, but I get the same error at runtime.

The question

How do I resolve this?

  • What exactly needs rebuilding? usb-detection isn't listed in the dependencies (or the devDependencies) but if I'm not mistaken node-usb-native depends on it.
  • How do I go about this such that the code complaining about versions sees the freshly minted bits?
0

There are 0 answers