question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to require node-hid in Travis CI

See original GitHub issue

When requiring node-hid in Travis-CI I get this error “cannot initialize hidapi (hid_init failed)”.

I am unable to run unit tests on modules that use node-hid on Travis-CI because this error is thrown when node-hid is required. I have tried to stub out the module in my tests without any luck. I have traced this to https://github.com/node-hid/node-hid/blob/master/src/HID.cc#L583. This code is being run when the module is required and I think this should be done when the HID instance is created.

const HID = require('node-hid'); // Is thrown her.

const device = new HID.HID(path); // Should be thrown her.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
todbotcommented, Jan 29, 2017

I believe this has been fixed in the latest release. We’re currently doing builds in Travis too. Thanks for your patience.

0reactions
agirorncommented, Oct 22, 2016

Thanks, that does work.

Only because mockery is so overly aggressive when it does it’s mocking.

You can get node-hid to install on travice by adding this to travis.yml.

before_install:
  - sudo apt-get update
  - sudo apt-get install build-essential git -y
  - sudo apt-get install libudev-dev -y
  - sudo apt-get install libusb-1.0-0-dev -y
  - sudo apt-get install gcc-4.8 g++-4.8 -y
  - if [[ `npm -v` != 3* ]]; then npm i -g npm@3; fi

I still think that node-hid should not start executing this code when the module is required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Do not execute code on `require`. · Issue #226 · node-hid/node-hid ...
Node -hid is used in one particular code path in my application yet I can't run any of my tests in Docker or...
Read more >
Building a JavaScript and Node.js project - Travis CI Docs
This guide covers build environment and configuration topics specific to JavaScript and Node.js projects. Please make sure to read our Tutorial and general ......
Read more >
Travis CI: file from node module not found - Stack Overflow
The simplest way to get out of this situation is $ git add --force node_modules/mocha.css node_modules/mocha.js $ git commit -m "Add the ...
Read more >
node-hid - UNPKG
The CDN for node-hid. ... Build Status](https://travis-ci.org/libusb/hidapi.svg?branch=master)](https:// ... It requires kernel version at least 2.6.39.
Read more >
binance-chain-javascript-sdk-remove-node-hid - npm package
Unable to verify the project's public source code repository. Advisor · JavaScript packages · binance-chain-javascript-sdk-remove-node ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found