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.

Can't use node-usb with electron react applicaiton.

See original GitHub issue

Hello I’m trying to use this node-usb library for my electron react application but when I run the code inside the electron container, I get an error like this:

bindings.js:178 Uncaught TypeError: Cannot read property 'indexOf' of undefined
    at Function.t.getFileName (bindings.js:178)
    at t (bindings.js:82)
    at Object.<anonymous> (usb.js:1)
    at Object.<anonymous> (2.5fedd273.chunk.js:2)
    at l (index.html:1)
    at Module.66 (usbAccessButton.component.jsx:5)
    at l (index.html:1)
    at Object.41 (main.2cdae987.chunk.js:1)
    at l (index.html:1)
    at f (index.html:1)

This is how my react component looks:

import React from 'react';

import Button from 'react-bootstrap/Button';

var usb = require('usb');

class UsbAccessButton extends React.Component {

  render() {
      return <Button>Get USB Access</Button>
  }
}

export default UsbAccessButton;

And this is how the app.js looks:

import React from 'react';

import './App.css';

import UsbAccessButton from './components/usb-access-button/usbAccessButton.component';

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <UsbAccessButton />
      </header>
    </div>
  );
}

export default App;

I’m not using webpack and my package.json is this:

{
  "name": "test",
  "homepage": ".",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "bootstrap": "^4.4.1",
    "electron": "^7.1.9",
    "react": "^16.12.0",
    "react-bootstrap": "^1.0.0-beta.16",
    "react-dom": "^16.12.0",
    "react-scripts": "3.3.0",
    "usb": "^1.6.2"
  },
  "main": "src/main.js",
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "electron": "react-scripts build && electron ."
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
thegeckocommented, Oct 18, 2021
1reaction
thegeckocommented, Jul 15, 2021

Please ensure you are running node-usb in the backend process of Electron

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't use node-usb with electron react applicaiton. · Issue #349
Hello I'm trying to use this node-usb library for my electron react application but when I run the code inside the electron container, ......
Read more >
Why is Nodejs usb module conflicting with Electron?
This version of Node.js requires NODE_MODULE_VERSION 85. Please try re-compiling or re-installing the module (for instance, using `npm ...
Read more >
How to build an Electron app using create-react-app ... - Medium
I recently built an Electron app using create-react-app. I didn't need to muck about with Webpack, or “eject” my app, either. I'll walk...
Read more >
Developers - Can't use node-usb with electron react applicaiton. -
Hello I'm trying to use this node-usb library for my electron react application but when I run the code inside the electron container,...
Read more >
Node USB
On Windows, if you get LIBUSB_ERROR_NOT_SUPPORTED when attempting to open your device, it's possible your device doesn't have a WinUSB driver for libusb...
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