Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Error: Could not locate the bindings file. #40

Closed
johnvs opened this issue Mar 19, 2017 · 1 comment
Closed

Uncaught Error: Could not locate the bindings file. #40

johnvs opened this issue Mar 19, 2017 · 1 comment

Comments

@johnvs
Copy link

johnvs commented Mar 19, 2017

I am trying to use the package serialport in a project with no success. I have simplified the project to the following:

  1. Created a new Bozon project with bozon new bozon-serialport-test.
  2. Run bozon start to verify that the project works as expected.
  3. To the top of app/renderer/application.js, added the line
    const Serialport = require('serialport);.

Doing this results in the following error.

application.js:2024 Uncaught Error: Could not locate the bindings file. Tried:
→ /Users/john/Documents/Software_Development/Node/bozon_serialport_test/build/serialport.node
→ /Users/john/Documents/Software_Development/Node/bozon_serialport_test/build/Debug/serialport.node
→ /Users/john/Documents/Software_Development/Node/bozon_serialport_test/build/Release/serialport.node
→ /Users/john/Documents/Software_Development/Node/bozon_serialport_test/out/Debug/serialport.node
→ /Users/john/Documents/Software_Development/Node/bozon_serialport_test/Debug/serialport.node
→ /Users/john/Documents/Software_Development/Node/bozon_serialport_test/out/Release/serialport.node
→ /Users/john/Documents/Software_Development/Node/bozon_serialport_test/Release/serialport.node
→ /Users/john/Documents/Software_Development/Node/bozon_serialport_test/build/default/serialport.node
→ /Users/john/Documents/Software_Development/Node/bozon_serialport_test/compiled/6.5.0/darwin/x64/serialport.node

The correct path is /Users/john/Documents/Software_Development/Node/bozon_serialport_test/builds/development/node_modules/serialport/build/Release/serialport.node.

As suggested here, I ran the (slightly modified) command ./app/node_modules/.bin/electron-rebuild (since the app node_modules dir is where serialport is). I get the same result.

Also from that page, I tried HOME=~/.electron-gyp node-gyp rebuild --target=1.4.15 --arch=x64 --dist-url=https://atom.io/download/electron and got the same result.

I also read through this post and tried the following:

  1. Installed node-pre-gyp globally with yarn global node-pre-gyp.
  2. In the directory . . .bozon_serialport_test/app/node_modules/serialport, I executed node-pre-gyp rebuild.
  3. I ran the project again and got the same error.

I am using:
electron 1.4.15,
bozon 0.7.0,
OS X 10.11.6

What is generating those incorrect paths? Is there anything else to try to make this work?

@johnvs
Copy link
Author

johnvs commented Mar 21, 2017

This appears to be a webpack issue. Because serialport is a binary file, it needs to be excluded from webpack. One solution for accomplishing this is adding an 'externals' property to the webpack configuration object in the file bozon/lib/building/tasks.js.

externals: [
    (function () {
      var IGNORES = [
        'electron'
      ];
      return function (context, request, callback) {
        if (IGNORES.indexOf(request) >= 0) {
          return callback(null, "require('" + request + "')");
        }
        return callback();
      };
    })()
]

An even easier solution is changing the require statement ever so slightly:
WAS: const Serialport = require('serialport');
IS: const Serialport = window.require('serialport');

The original answer is here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants