title: Error with Node Serialport used in electron + react (webpack)
body: <p>I'm trying to build a cross-platform App using electron and react. This App shall be used to communicate with a serial device using Node Serialport. And to tell you right at the beginning: I am new to the node.js stuff including electron and react.js)</p>
  
  <p>I followed various guides to rebuild Node Serialport for electron having a hard time. In the end I am sure I got it correctly rebuild.</p>
  
  <p>When I use the workaround from <a href="https://stackoverflow.com/questions/46442623/node-serial-port-as-external-module-in-webpack-module-not-found">Patryk at Stackoverflow</a> and put </p>
  
  <pre><code>&lt;script&gt;
    const sp = require('serialport');
    var sPort = sp('/dev/ttyACM0', {baudRate: 115200})
    sPort.write(new Uint8Array([0xff, 0x41, 0x01, 0x00, 0x42, 0xee]))
  &lt;/script&gt;
  </code></pre>
  
  <p>into <code>index.hmtl</code> I can communicate with my serial device. But I don't know how I can make use of the serial connection in my further <code>.js</code>-files like <code>App.js</code>.</p>
  
  <p>When I put</p>
  
  <pre><code>var SerialPort = require('serialport');
  </code></pre>
  
  <p>or</p>
  
  <pre><code>var SerialPort = require( "electron" ).remote.require( "serialport" );
  </code></pre>
  
  <p>into my <code>.js</code>-files I get the following Errors/Warnings:</p>
  
  <p>Console output from <code>npm run dev</code></p>
  
  <pre><code>09:48:02 react.1      |  Compiling...
  09:48:04 react.1      |  Compiled with warnings.
  09:48:04 react.1      |  ./src/App.js
  09:48:04 react.1      |    Line 7:  'SerialPort' is assigned a value but never used  no-unused-vars
  09:48:04 react.1      |  ./node_modules/bindings/bindings.js
  09:48:04 react.1      |  81:22-40 Critical dependency: the request of a dependency is an expression
  09:48:04 react.1      |  ./node_modules/bindings/bindings.js
  09:48:04 react.1      |  81:43-53 Critical dependency: the request of a dependency is an expression
  09:48:04 react.1      |  Search for the keywords to learn more about each warning.
  09:48:04 react.1      |  To ignore, add // eslint-disable-next-line to the line before.
  </code></pre>
  
  <p>Error message in electron window:</p>
  
  <pre><code>TypeError: exists is not a function
  Function.getRoot
  node_modules/bindings/bindings.js:158
    155 |   // Avoids an infinite loop in rare cases, like the REPL
    156 |   dir = process.cwd()
    157 | }
  &gt; 158 | if (exists(join(dir, 'package.json')) || exists(join(dir, 'node_modules'))) {
    159 |   // Found the 'package.json' file or 'node_modules' dir; we're done
    160 |   return dir
    161 | }
  View compiled
  bindings
  node_modules/bindings/bindings.js:60
    57 | 
    58 | // Get the module root
    59 | if (!opts.module_root) {
  &gt; 60 |   opts.module_root = exports.getRoot(exports.getFileName())
    61 | }
    62 | 
    63 | // Ensure the given bindings name ends with .node
  View compiled
  ./node_modules/@serialport/bindings/lib/linux.js
  node_modules/@serialport/bindings/lib/linux.js:1
  &gt; 1 | const binding = require('bindings')('bindings.node')
    2 | const AbstractBinding = require('@serialport/binding-abstract')
    3 | const linuxList = require('./linux-list')
    4 | const Poller = require('./poller')
  View compiled
  __webpack_require__
  /home/bas/Documents/Projects/MicroGator/Code/GatorRemoteElectron/webpack/bootstrap 89408b2d7db2f964ac18:678
    675 | };
    676 | 
    677 | // Execute the module function
  &gt; 678 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
    679 | 
    680 | // Flag the module as loaded
    681 | module.l = true;
  View compiled
  fn
  /home/bas/Documents/Projects/MicroGator/Code/GatorRemoteElectron/webpack/bootstrap 89408b2d7db2f964ac18:88
    85 |      console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
    86 |      hotCurrentParents = [];
    87 |  }
  &gt; 88 |  return __webpack_require__(request);
    89 | };
    90 | var ObjectFactory = function ObjectFactory(name) {
    91 |  return {
  View compiled
  (anonymous function)
  node_modules/@serialport/bindings/lib/index.js:14
    11 |     break
    12 |   default:
    13 |     debug('loading LinuxBinding')
  &gt; 14 |     module.exports = require('./linux')
    15 | }
    16 | 
    17 | 
  View compiled
  ./node_modules/@serialport/bindings/lib/index.js
  http://localhost:5000/static/js/bundle.js:18558:30
  __webpack_require__
  /home/bas/Documents/Projects/MicroGator/Code/GatorRemoteElectron/webpack/bootstrap 89408b2d7db2f964ac18:678
    675 | };
    676 | 
    677 | // Execute the module function
  &gt; 678 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
    679 | 
    680 | // Flag the module as loaded
    681 | module.l = true;
  View compiled
  fn
  /home/bas/Documents/Projects/MicroGator/Code/GatorRemoteElectron/webpack/bootstrap 89408b2d7db2f964ac18:88
    85 |      console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
    86 |      hotCurrentParents = [];
    87 |  }
  &gt; 88 |  return __webpack_require__(request);
    89 | };
    90 | var ObjectFactory = function ObjectFactory(name) {
    91 |  return {
  View compiled
  ./node_modules/serialport/lib/index.js
  node_modules/serialport/lib/index.js:2
    1 | const SerialPort = require('@serialport/stream')
  &gt; 2 | const Binding = require('@serialport/bindings')
    3 | const parsers = require('./parsers')
    4 | 
    5 | /**
  View compiled
  __webpack_require__
  /home/bas/Documents/Projects/MicroGator/Code/GatorRemoteElectron/webpack/bootstrap 89408b2d7db2f964ac18:678
    675 | };
    676 | 
    677 | // Execute the module function
  &gt; 678 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
    679 | 
    680 | // Flag the module as loaded
    681 | module.l = true;
  View compiled
  fn
  /home/bas/Documents/Projects/MicroGator/Code/GatorRemoteElectron/webpack/bootstrap 89408b2d7db2f964ac18:88
    85 |      console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
    86 |      hotCurrentParents = [];
    87 |  }
  &gt; 88 |  return __webpack_require__(request);
    89 | };
    90 | var ObjectFactory = function ObjectFactory(name) {
    91 |  return {
  View compiled
  ./src/App.js
  src/App.js:7
    4 | 
    5 | import 'typeface-roboto'
    6 | 
  &gt;  7 | var SerialPort = require('serialport');;
    8 | 
    9 | class App extends Component {
    10 |   render() {
  </code></pre>
  
  <p>My App.js looks like this:</p>
  
  <pre><code>import React, { Component } from 'react';
  import TargetTabs from './components/TargetTabs'
  import './App.css';
  
  import 'typeface-roboto'
  
  var SerialPort = require('serialport');
  
  class App extends Component {
    render() {
      return (
      &lt;div&gt;
        &lt;TargetTabs /&gt;
      &lt;/div&gt;
      );
    }
  }
  
  export default App;
  </code></pre>
  
  <p>So if you could point me in the right direction to either use the variable from the script block in <code>index.html</code> in my other <code>js</code>-files or to solve the warnings/errors so that i can use the standard require, I would be very grateful.</p>
  
  <p>Perhaps even both ... :)</p>