Can't use node-usb with electron react applicaiton.
See original GitHub issueHello 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:
- Created 4 years ago
- Comments:11 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This simple example may help you:
https://github.com/node-usb/node-usb-example-electron
Please ensure you are running
node-usb
in the backend process of Electron