Code Monkey home page Code Monkey logo

node-bindings's Introduction

node-bindings

Helper module for loading your native module's .node file

This is a helper module for authors of Node.js native addon modules. It is basically the "swiss army knife" of require()ing your native module's .node file.

Throughout the course of Node's native addon history, addons have ended up being compiled in a variety of different places, depending on which build tool and which version of node was used. To make matters worse, now the gyp build tool can produce either a Release or Debug build, each being built into different locations.

This module checks all the possible locations that a native addon would be built at, and returns the first one that loads successfully.

Installation

Install with npm:

$ npm install --save bindings

Or add it to the "dependencies" section of your package.json file.

Example

require()ing the proper bindings file for the current node version, platform and architecture is as simple as:

var bindings = require('bindings')('binding.node')

// Use your bindings defined in your C files
bindings.your_c_function()

Nice Error Output

When the .node file could not be loaded, node-bindings throws an Error with a nice error message telling you exactly what was tried. You can also check the err.tries Array property.

Error: Could not load the bindings file. Tried:
 → /Users/nrajlich/ref/build/binding.node
 → /Users/nrajlich/ref/build/Debug/binding.node
 → /Users/nrajlich/ref/build/Release/binding.node
 → /Users/nrajlich/ref/out/Debug/binding.node
 → /Users/nrajlich/ref/Debug/binding.node
 → /Users/nrajlich/ref/out/Release/binding.node
 → /Users/nrajlich/ref/Release/binding.node
 → /Users/nrajlich/ref/build/default/binding.node
 → /Users/nrajlich/ref/compiled/0.8.2/darwin/x64/binding.node
    at bindings (/Users/nrajlich/ref/node_modules/bindings/bindings.js:84:13)
    at Object.<anonymous> (/Users/nrajlich/ref/lib/ref.js:5:47)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    ...

The searching for the .node file will originate from the first directory in which has a package.json file is found.

License

(The MIT License)

Copyright (c) 2012 Nathan Rajlich <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

node-bindings's People

Contributors

andrewrk avatar anion155 avatar arcanis avatar n-riesco avatar nickzuber avatar rvagg avatar tootallnate avatar vihanb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-bindings's Issues

Documentation on using with webpack

I just discovered after some digging that, for a module to work with node-bindings in a project that uses webpack, that module needs to be included in externals in webpack.config.js so that its code ends up in a directory from which its package.json can be found. Would it make sense to include this in the readme?

Cannot minify easily because of a getter with side-effect

I was minifying a project with a package depending on node-bindings and the resulting code ended up throwing an exception regarding some path not being a string.

I pinpointed the problem in getRoot which led to the realization that getFileName was returning undefined. Finally, I spotted the culprit: dummy.stack (https://github.com/TooTallNate/node-bindings/blob/master/bindings.js#L168).

Most minifiers will remove code with no side effect, just like getting a property of an object while seemingly not having any use for it.

Since I use uglify-es, I'm able to set the pure_getters compress option to false, which instructs the minifier to be extra-conservative regarding object property accesses.

I dunno if this is something you'd like to "fix" but I thought people should know in case they encounter the same issue.

Additional paths not found

Hi,

Here's a feature proposal, It'd be really convenient to add extra platform paths to the bindings.js default dictionary, ie:

[ 'module_root', 'build', 'Release_x64', 'bindings' ]
[ 'module_root', 'build', 'Debug_x64', 'bindings' ]

Some vs projects like ANGLE place their content in this type folders on windows it becomes very handy being able to put directly the nodejs addons on such folders, so they can use their dlls directly without messing around.

Thanks.

Bindings error io.js 1.0.3

Hello,

i tried to use bcrypt with io.js today and got this error:

node_modules/bcrypt/node_modules/bindings/bindings.js:79
throw e
^
Error: Module did not self-register.
at Error (native)
at Module.load (module.js:341:32)
at Function.Module._load (module.js:296:12)
at Module.require (module.js:351:17)
at require (module.js:370:17)

Do you already know this issue?

Best regards
Dominic

Cannot read property 'indexOf' of undefined

PS F:\www\zuhao\client> yarn debug:main
yarn run v1.13.0
$ electron --inspect=5858 -w ./dist/main/main.js

Debugger listening on ws://127.0.0.1:5858/0977f6ec-8de8-4e54-a2d5-09ad8d82aabe
For help, see: https://nodejs.org/en/docs/inspector
App threw an error during load
TypeError: Cannot read property 'indexOf' of undefined
at Function.t.getFileName (F:\www\zuhao\client\dist\main\main.js:139:211412)
at t (F:\www\zuhao\client\dist\main\main.js:139:210566)
at Object. (F:\www\zuhao\client\dist\main\main.js:1:74523)
at a (F:\www\zuhao\client\dist\main\main.js:1:110)
at Object. (F:\www\zuhao\client\dist\main\main.js:223:156632)
at a (F:\www\zuhao\client\dist\main\main.js:1:110)
at Object. (F:\www\zuhao\client\dist\main\main.js:139:219468)
at a (F:\www\zuhao\client\dist\main\main.js:1:110)
at F:\www\zuhao\client\dist\main\main.js:1:902
at Object. (F:\www\zuhao\client\dist\main\main.js:1:913)

when i package electron ,has this error。 thanks for you help,realy need help

Can't resolve 'fs'

I'm using a package that includes node-hid which includes bindings, and I get this:

How can I fix this?

ERROR in ./node_modules/bindings/bindings.js
Module not found: Error: Can't resolve 'fs' in 'f:\Github\stellar-client-web\node_modules\bindings'
@ ./node_modules/bindings/bindings.js 6:9-22
@ ./node_modules/node-hid/nodehid.js
@ ./node_modules/@ledgerhq/hw-transport-node-hid/lib/TransportNodeHid.js
@ ./node_modules/stellar-js-utils/dist/build.js
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/pages/CreateToken.vue
@ ./src/pages/CreateToken.vue
@ ./src/libEntry.js
@ ./src/entry.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/entry.js

WARNING in ./node_modules/bindings/bindings.js
81:22-40 Critical dependency: the request of a dependency is an expression
@ ./node_modules/bindings/bindings.js
@ ./node_modules/node-hid/nodehid.js
@ ./node_modules/@ledgerhq/hw-transport-node-hid/lib/TransportNodeHid.js
@ ./node_modules/stellar-js-utils/dist/build.js
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/pages/CreateToken.vue
@ ./src/pages/CreateToken.vue
@ ./src/libEntry.js
@ ./src/entry.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/entry.js

WARNING in ./node_modules/bindings/bindings.js
81:43-53 Critical dependency: the request of a dependency is an expression
@ ./node_modules/bindings/bindings.js
@ ./node_modules/node-hid/nodehid.js
@ ./node_modules/@ledgerhq/hw-transport-node-hid/lib/TransportNodeHid.js
@ ./node_modules/stellar-js-utils/dist/build.js
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/pages/CreateToken.vue
@ ./src/pages/CreateToken.vue
@ ./src/libEntry.js
@ ./src/entry.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/entry.js

would this module be used to find an executable?

For example if binding.gyp has a target of type "executable" this gets put in build/Release/* somewhere. would/could/should this bindings module be used to find the path?

Part of the problem this would solve would be that on Windows the executable would have a .exe extension and on posix systems it would not.

Device not ready errors when attempting to resolve path for bindings file

I've been debugging a bunch of build failures that seem to stem from virtual machines in my build environment (physical machines seem to be fine). This is super weird.

It looks like all the builds fail when we try to run this line in our tests, bindings.js line 76:

b = opts.path ? require.resolve(n) : require(n)

I've boiled it down to something even simpler:

b = require("C:\\odbc_node.js");

We see a lot of "Error: The device is not ready"

The odbc_node.js file we get by extracting this: https://github.com/ibmdb/node-ibm_db/blob/master/build.zip

Any ideas?

Unicode in error messages

I think the unicode chars in the error message are unnecessary. They do not convey any information but increase the chances of garbled console output. Just think about debugging DLL issues on a remote continuous integration server. The last thing you'd need is more noise in the logs. bindings() acts as a shim and thus should be as invisible as possible.

We could make it configurable using env vars and options and stuff. But we could also just use ASCII.

Error: Module version mismatch. Expected 48, got 59.

Bindings was introduced by using inotify. A test program I've made in the same project, using only inotify, works without problems.

When I start my node/express application I get the following error.

~/workspace/adoc2html/node_modules/bindings/bindings.js:88
        throw e
        ^

Error: Module version mismatch. Expected 48, got 59.
    at Error (native)
    at Object.Module._extensions..node (module.js:597:18)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at bindings (/home/VERUM.COM/maartenvandewaarsenb/workspace/adoc2html/node_modules/bindings/bindings.js:81:44)
    at Object.<anonymous> (/home/VERUM.COM/maartenvandewaarsenb/workspace/adoc2html/node_modules/inotify/inotify.js:1:99)
    at Module._compile (module.js:570:32)
maartenvandewaarsenb@vpce020:~/workspace/adoc2html$

I'm using node v9.2.0 and npm 5.8.0 on Ubuntu 17.10.

I've rebuilt (npm install) node_modules from scratch (tried yarn as well) but I keep getting this error.

How should I proceed to get it working?

Is it working on electron and support webpack?(mac os x 10.12.6)

Hi,
When using node-ffi(ps: i know node-ffi also maintained by you.) in electron to load DynamicLibrary. there is a problem when executing require('ffi'), and the error log in electron console:

Uncaught ReferenceError: bindings is not defined
at Object.<anonymous> (external "bindings":1)
at e (bootstrap:44)
at Object.<anonymous> (ref.js:5)
at e (bootstrap:44)
at Object.<anonymous> (ffi.js:6)
at e (bootstrap:44)
at Module.<anonymous> (Clipboard.js:4)
at e (bootstrap:44)
at Module.<anonymous> (index.js:10)
at e (bootstrap:44)

and i use webpack 4 to build source code.
Wanted to know if bindings support electron 4.0.1 | webpack 4 on mac os x 10.12.6. thanks~

Option to vendor binding files in top-level app?..

hey there 👋

thanks for the super-helpful lib 🙏

i'm looking for a way to "vendor" the binding files for my app such that dependencies (e.g. @serialport/bindings) use the vendor'ed bindings files provided by the root app instead of their module-local default. i don't see a way to do this - am i just missing it?

very roughly, you could:

  1. determine the app_root (perhaps via app-root-path)
  2. determine module_name (the package.json name field for the module - e.g. @serialport/bindings)
  3. add a lookup entry to the list here which is resolved first and attempts to load from a path like:
['app_root', 'vendor', 'module_name',  `abi-v${process.versions.modules}`, 'platform', 'arch', 'bindings']

...does that make sense and fit with your goals for this lib? happy to create a PR if so!

related: serialport/node-serialport#2044

Webpack Issues

Hi,
when using webpack with this package, two warnings occure:

WARNING in ./~/bindings/bindings.js
Critical dependencies:
76:22-40 the request of a dependency is an expression
76:43-53 the request of a dependency is an expression
 @ ./~/bindings/bindings.js 76:22-40 76:43-53

WARNING in ./~/bindings/README.md
Module parse failed: /path/to/my/app/node_modules/bindings/README.md Unexpected token (2:3)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:3)
    at Parser.pp.raise (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:920:13)
    at Parser.pp.unexpected (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:1483:8)
    at Parser.pp.parseExprAtom (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:330:12)
    at Parser.pp.parseExprSubscripts (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:225:19)
    at Parser.pp.parseMaybeUnary (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:204:17)
    at Parser.pp.parseExprOp (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:171:41)
    at Parser.pp.parseExprOp (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:173:19)
    at Parser.pp.parseExprOps (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:153:15)
    at Parser.pp.parseMaybeConditional (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:133:19)
    at Parser.pp.parseMaybeAssign (/path/to/my/app/node_modules/webpack/node_modules/acorn/dist/acorn.js:110:19)
 @ ./~/bindings ^\.\/.*$

The first complains about dynamic imports. The webpack guys think that they should not be used at all. I don't know if that is even possible in this case. The second one obviously is webpack trying to parse the readme for some reason 😄 .

Dynamic require() calls produce a warning in webpack

My webpack builds currently produce the following warning for webpack { target: 'node' } (but not for { target: 'web' }:

WARNING in ./node_modules/bindings/bindings.js
81:22-40 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/bindings/bindings.js
 ...

This is the line that produces the warning:

b = opts.path ? require.resolve(n) : require(n)

Versions:

bindings: 1.3.0
npm: 5.5.1
node: 8.2.0
webpack: 3.10.0
babel-core: 6.26.0
babel-loader: 7.1.2
babel-plugin-transform-es3-member-expression-literals: 6.22.0
babel-plugin-transform-es3-property-literals: 6.22.0
babel-plugin-transform-object-rest-spread: 6.26.0
babel-preset-es2015: 6.24.1

Error.prepareStackTrace may not be called with webpack

While trying to understand why when bindings was used with webpack it returned this kind of error:

TypeError: Cannot read property 'indexOf' of undefined
When calling getFileName

I noticed that webpack, when configured to build for production, appears to be very agressive and simply removes this line from bindings.js:

Error.captureStackTrace(dummy);
dummy.stack // <- this line gets stripped from the build

As a consequence, Error.prepareStackTrace that is defined above never gets called (that's because that the Error.prepareStackTrace is supposed to be called when the stack property is accessed), and this explains why there is a crash since fileName is undefined when this line is called:

  if (fileName.indexOf(fileSchema) === 0) {
    fileName = fileURLToPath(fileName);
  }

I created a small project that shows the problem: https://github.com/warpdesign/bindings-webpack

Simply checkout the repository, call npm install && npm run build and then open the build/main.js file.

Notice how the .stack property access is missing:

Error.captureStackTrace(i),/* stack property access should be there */Error.prepareStackTrace=o

Feature request: multiple installed bindings

There's token support for loading different bindings based on architecture and node version, but it would be nice to see more robust support for node-sqlite3-style binding build/install. In particular:

  • add the lib/binding/Release/<arch and version string>/foo.node path style used by node-sqlite3
  • add a default build script along the lines of node-sqlite3's "build.js" so this doesn't have to be cut-and-pasted into every module.

Unclear how to specify versioning

It looks like bindings has changed to use the full version number but the README still says to use parseFloat(process.versions.node). Does this also imply that I should be building binaries for every possible major.minor.revision, an unfortunate reality but perhaps unavoidable?

uncaught Error: Could not find module root given file: "app://./js/chunk-vendors.a960702b.js". Do you have a `package.json` file?

stacktrace:

Uncaught Error: Could not find module root given file: "app://./js/chunk-vendors.a960702b.js". Do you have a package.json file?
at Function.getRoot (bindings.js:211)
at bindings (bindings.js:82)
at Object.0e66 (ref.js:5)
at webpack_require (bootstrap:84)
at Module.cd49 (app.f8c3ff0a.js:1)
at webpack_require (bootstrap:84)
at Object.0 (app.f8c3ff0a.js:1)
at webpack_require (bootstrap:84)
at checkDeferredModules (bootstrap:45)
at bootstrap:221

i am using https://github.com/nklayman/vue-cli-plugin-electron-builder to pack my electron app.
all my bussiness-related codes are packed together and can be accessed with customed app protocol.
file system structure:

|-- omitted...
|-- js
|   |-- omitted...
|   |-- chunk-vendors.a960702b.js
|   `-- chunk-vendors.a960702b.js.map
|-- node_modules
|   |-- bindings
|   |-- omitted...
`-- package.json

i dived inside bindings code, and it seems lack of supporting this kind of customized protocol such as app.
do i have to bring in a app-uri-to-path module and use customized version of node-bindings?
any suggestion?

is it working with webpack?

I got the following message while building with webpack:
`WARNING in ./~/bindings/bindings.js
81:22-40 Critical dependency: the request of a dependency is an expression

WARNING in ./~/bindings/bindings.js
81:43-53 Critical dependency: the request of a dependency is an expression

WARNING in .//ffi//bindings/bindings.js
82:28-46 Critical dependency: the request of a dependency is an expression

WARNING in .//ffi//bindings/bindings.js
82:49-59 Critical dependency: the request of a dependency is an expression
`

node: 7.7.4
npm: 4.1.2
webpack: 2.2

getFileName cannot read property of undefined

Seeing the below when using https://github.com/jostrander/mouse-forward-back in our project (lbryio/lbry-desktop@cd8436c). We are using webpack 3.

      at Function.getFileName (webpack-internal:///./node_modules/bindings/bindings.js:176:16)
      at bindings (webpack-internal:///./node_modules/bindings/bindings.js:82:48)
      at eval (webpack-internal:///./node_modules/mouse-forward-back/mouse-forward-back.js:3:82)
      at Object../node_modules/mouse-forward-back/mouse-forward-back.js (/home/tom/lbry-desktop/dist/main/main.js:739:1)
      at __webpack_require__ (/home/tom/lbry-desktop/dist/main/main.js:655:30)
      at fn (/home/tom/lbry-desktop/dist/main/main.js:65:20)
      at __webpack_exports__.a.appState (webpack-internal:///./src/main/createWindow.js:18:24)
      at App.eval (webpack-internal:///./src/main/index.js:120:91)
      at Generator.next (<anonymous>)
      at step (webpack-internal:///./src/main/index.js:24:191)

Module did not self-register.

hi,

I am cross-posting this, because it is unclear to me where exactly this error originates from. but it looks like it has s.th. to do with wither gulp-mocha or node-bindings, or a combination.

error:

[...]

[12:35:24] Starting 'mocha'...
[12:35:24] 'mocha' errored after 35 ms
[12:35:24] Error in plugin 'gulp-mocha'
Message:
    Module did not self-register.
Stack:
Error: Module did not self-register.
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at bindings (/Volumes/Macintosh HD 2/Projects/project/code/project.js/node_modules/libxmljs/node_modules/bindings/bindings.js:76:44)
    at Object.<anonymous> (/Volumes/Macintosh HD 2/Projects/project/code/project.js/node_modules/libxmljs/lib/bindings.js:1:99)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)

full info over at gulp-mocha.

window 7 election add ffi error of version diffenet

App threw an error during load
Error: The module '\?\D:\workspace\shca-xkapp-admin\node_modules\ref\build\Release\binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 64. This version of Node.js requires
NODE_MODULE_VERSION 73. Please try re-compiling or re-installing

package.json

  "devDependencies": {
    "debug": "^4.1.1",
    "devtron": "^1.4.0",
    "electron": "^6.0.9",
    "glob": "^7.1.4",
    "json5": "^2.1.0",
    "lodash": "^4.17.15",
    "supports-color": "^7.0.0",
    "uuid": "^3.3.3",
    "ws": "^7.1.2"
  },
  "dependencies": {
    "ffi": "^2.3.0"
  }

Error: The specified module could not be found. But the file Exists

The file exists. Any idea how to fix it?

> > [email protected] test E:\node-iohook
> > node test.js "config"
> 
> E:\node-iohook\node_modules\bindings\bindings.js:83
>         throw e
>         ^
> 
> Error: The specified module could not be found.
> \\?\E:\node-iohook\build\Release\node-iohook.node
>     at Error (native)
>     at Object.Module._extensions..node (module.js:568:18)
>     at Module.load (module.js:456:32)
>     at tryModuleLoad (module.js:415:12)
>     at Function.Module._load (module.js:407:3)
>     at Module.require (module.js:466:17)
>     at require (internal/module.js:20:19)
>     at bindings (E:\node-iohook\node_modules\bindings\bindings.js:76:44)
>     at Object.<anonymous> (E:\node-iohook\test.js:1:104)
>     at Module._compile (module.js:541:32)
>  npm ERR! code ELIFECYCLE
> npm ERR! errno 1
> npm ERR! [email protected] test: `node test.js "config"`
> npm ERR! Exit status 1

Debian, Node v6: Could not locate the bindings file

I'm not sure if this is an issue with deasync or node-bindings with Node v6.

The deasync issue is here: abbr/deasync#58

  err = new Error('Could not locate the bindings file. Tried:\n'
        ^
Error: Could not locate the bindings file. Tried:
 → /usr/src/app/node_modules/deasync/build/deasync.node
 → /usr/src/app/node_modules/deasync/build/Debug/deasync.node
 → /usr/src/app/node_modules/deasync/build/Release/deasync.node
 → /usr/src/app/node_modules/deasync/out/Debug/deasync.node
 → /usr/src/app/node_modules/deasync/Debug/deasync.node
 → /usr/src/app/node_modules/deasync/out/Release/deasync.node
 → /usr/src/app/node_modules/deasync/Release/deasync.node
 → /usr/src/app/node_modules/deasync/build/default/deasync.node
 → /usr/src/app/node_modules/deasync/compiled/6.0.0/linux/x64/deasync.node
    at bindings (/usr/src/app/node_modules/bindings/bindings.js:88:9)
    at /usr/src/app/node_modules/deasync/index.js:34:32
    at Object.<anonymous> (/usr/src/app/node_modules/deasync/index.js:76:2)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Module.require (module.js:466:17)
    at require (internal/module.js:20:19)

npm info lifecycle [email protected]~start: Failed to exec start script
npm ERR! Linux 4.4.5-15.26.amzn1.x86_64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.0.0
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE```

different NODE_MODULE_VERSION ?

usb_bindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 73. Please try re-compiling or re-installing
--But i cann't found Node.js version using
NODE_MODULE_VERSION 73?

throw e on bindings.js

/Users/KING/Desktop/dashboard/node_modules/leveldown/node_modules/bindings/bindings.js:83
throw e
^

Error: dlopen(/Users/KING/Desktop/dashboard/node_modules/leveldown/build/Release/leveldown.node, 1): no suitable image found. Did find:
/Users/KING/Desktop/dashboard/node_modules/leveldown/build/Release/leveldown.node: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
/Users/KING/Desktop/dashboard/node_modules/leveldown/build/Release/leveldown.node: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
at Object.Module._extensions..node (module.js:598:18)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at bindings (/Users/KING/Desktop/dashboard/node_modules/leveldown/node_modules/bindings/bindings.js:76:44)
at Object. (/Users/KING/Desktop/dashboard/node_modules/leveldown/leveldown.js:4:46)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)

Module mismatch

Getting mismatch version with node 8.
I found a work around by reverting node version to 4.8.0 but ideally I'd like to keep node at 8.

Any solutions?

Message = Error: Module version mismatch. Expected 48, got 57.

Will not check local directory for build

I have a project structure similar to something like this:

root/
|-- bin/
|-- src/
|-- scripts/
     |-- build/
     |-- src/
     |-- binding.gyp
     |-- run.js

Where scripts/src/ has my .cpp files for my node addon, and when I configure and build my addon, it gets compiled built into the scripts/build/ directory.

My run.js file looks like this:

'use strict';

require('bindings')('addon.node');

Whenever I try to run my run.js file, bindings isn't able to find my addon.node because it is checking my root directory instead of the local directory which has the actual build file:

Error: Could not locate the bindings file. Tried:
 → C:\~projects\root\build\addon.node
 → C:\~projects\root\build\Debug\addon.node
 → C:\~projects\root\build\Release\addon.node
 → C:\~projects\root\out\Debug\addon.node
 → C:\~projects\root\Debug\addon.node
 → C:\~projects\root\out\Release\addon.node
 → C:\~projects\root\Release\addon.node
 → C:\~projects\root\build\default\addon.node
 → C:\~projects\root\compiled\4.1.2\win32\x64\addon.node

I tried changing require('bindings')('addon.node'); to absolute paths, but bindings still tries to search the root directory instead of the local directory where my build directory is located.

Is this a bug in the program or am I approaching this / doing something wrong?

Error: Could not locate the bindings file. Tried:

bindings can't find the bin, but its there.
node v4-2-2, bcrypt v0.8.5

app-0 (err): Error: Could not locate the bindings file. Tried:
app-0 (err):  → /backend/node_modules/bcrypt/build/bcrypt_lib.node
app-0 (err):  → /backend/node_modules/bcrypt/build/Debug/bcrypt_lib.node
app-0 (err):  → /backend/node_modules/bcrypt/build/Release/bcrypt_lib.node
app-0 (err):  → /backend/node_modules/bcrypt/out/Debug/bcrypt_lib.node
app-0 (err):  → /backend/node_modules/bcrypt/Debug/bcrypt_lib.node
app-0 (err):  → /backend/node_modules/bcrypt/out/Release/bcrypt_lib.node
app-0 (err):  → /backend/node_modules/bcrypt/Release/bcrypt_lib.node
app-0 (err):  → /backend/node_modules/bcrypt/build/default/bcrypt_lib.node
app-0 (err):  → /backend/node_modules/bcrypt/compiled/4.2.2/linux/x64/bcrypt_lib.node
app-0 (err):     at bindings (/backend/node_modules/bindings/bindings.js:88:9)
app-0 (err):     at Object.<anonymous> (/backend/node_modules/bcrypt/bcrypt.js:3:35)
app-0 (err):     at Module._compile (module.js:435:26)
app-0 (err):     at Object.Module._extensions..js (module.js:442:10)
app-0 (err):     at Module.load (module.js:356:32)
app-0 (err):     at Function.Module._load (module.js:311:12)
app-0 (err):     at Function._load (/usr/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
app-0 (err):     at Module.require (module.js:366:17)
app-0 (err):     at require (module.js:385:17)
app-0 (err):     at Object.<anonymous> (/backend/lib/authentication.js:21:14)

$ ls -l node_modules/bcrypt/build/Release/bcrypt_lib.node
-rwxr-xr-x 1 vagrant vagrant 63653 Dec  2 12:58 node_modules/bcrypt/build/Release/bcrypt_lib.node

Uncaught Type error - exists is not a function. Integrating C library into node js

I am integrating a C library into a chrome app codebase that uses AngularJS and NodeJS as well. I am using node-ffi for integration. Though fs package is used at many places in the codebase, it throws error only at bindings.js code when I launch my application. I think it is trying to identify the ref and ffi modules related to my angular service that uses them. I did replace your fix in bindings.js file as below

, exists = ((fs.accessSync && function (path) { try { fs.accessSync(path); } catch (e) { return false; } return true; }) || fs.existsSync || path.existsSync)

Still I am getting the same error. Removing my ffi integration runs the chrome app well. @TooTallNate Could you please suggest me on this issue? It has been stopping my work from long time.

Error handling seems buggy on OS using an other language (not english)

image

/not find/i seems related to "est introuvable" in french... because this bug, I can not load native modules on Windows 7 French like better-sqlite3.

I think that you try to parse

$ node
> require('a')
Error: Cannot find module 'a'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

OK.. maybe it's an electron bug.. in the screenshot, I try to load the module with electron

Dynamic loading not supported on Alpine Linux

Hello,
I'm getting this error:

runway/node_modules/bindings/bindings.js:83
        throw e
        ^

Error: Dynamic loading not supported
    at Error (native)
    at Object.Module._extensions..node (module.js:568:18)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Module.require (module.js:466:17)
    at require (internal/module.js:20:19)
    at bindings (/opt/nord/runway/node_modules/bindings/bindings.js:76:44)
    at Object. (/opt/nord/runway/node_modules/ursa/lib/ursa.js:18:37)
    at Module._compile (module.js:541:32)

When running the following code on an Alpine Linux docker base image:

var ursa = require('ursa');
var fs = require('fs');
var crypt=fs.readFileSync('keyfile.pem', 'utf8');
var out = ursa.createPrivateKey(crypt, 'XXXXXX', 'utf8')
console.log(out.toPrivatePem('utf8'));

Ursa is a package that uses a .cc addon that's handled with node-bindings

Any insights?
Thank you!

Node v7: Could not locate the bindings file

/usr/local/lib/node_modules/pm2-web/node_modules/bindings/bindings.js:91
  throw err
  ^

Error: Could not locate the bindings file. Tried:
 → /usr/local/lib/node_modules/pm2-web/node_modules/pwuid/build/binding.node
 → /usr/local/lib/node_modules/pm2-web/node_modules/pwuid/build/Debug/binding.node
 → /usr/local/lib/node_modules/pm2-web/node_modules/pwuid/build/Release/binding.node
 → /usr/local/lib/node_modules/pm2-web/node_modules/pwuid/out/Debug/binding.node
 → /usr/local/lib/node_modules/pm2-web/node_modules/pwuid/Debug/binding.node
 → /usr/local/lib/node_modules/pm2-web/node_modules/pwuid/out/Release/binding.node
 → /usr/local/lib/node_modules/pm2-web/node_modules/pwuid/Release/binding.node
 → /usr/local/lib/node_modules/pm2-web/node_modules/pwuid/build/default/binding.node
 → /usr/local/lib/node_modules/pm2-web/node_modules/pwuid/compiled/7.5.0/darwin/x64/binding.node
    at bindings (/usr/local/lib/node_modules/pm2-web/node_modules/bindings/bindings.js:88:9)
    at Object.<anonymous> (/usr/local/lib/node_modules/pm2-web/node_modules/pwuid/index.js:2:34)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/pm2-web/server/components/Configuration.js:5:10)

Error.stackTraceLimit < 3 breaks getFileName

When something sets Error.stackTraceLimit to a value less than 3 the logic that searches for the caller's bindings fails. Will offer a pull request that temporarily sets it to the default 10 before and restores it afterwards.

Require error?

1|dtel     | Error: Module version mismatch. Expected 48, got 57.
1|dtel     |     at Error (native)
1|dtel     |     at Object.Module._extensions..node (module.js:597:18)
1|dtel     |     at Module.load (module.js:487:32)
1|dtel     |     at tryModuleLoad (module.js:446:12)
1|dtel     |     at Function.Module._load (module.js:438:3)
1|dtel     |     at Module.require (module.js:497:17)
1|dtel     |     at require (internal/module.js:20:19)
1|dtel     |     at bindings (/home/austin/node_modules/bindings/bindings.js:76:44)
1|dtel     |     at Object.<anonymous> (/home/austin/node_modules/node-opus/lib/OpusEncoder.js:4:34)
1|dtel     |     at Module._compile (module.js:570:32)
^C
[austin@runes ~]$ node -v
v8.0.0
[austin@runes ~]$ npm -v
5.0.0

getFileName does not work in electron

getFileName does not work in electron, In Electron, filename starts with "file://", it should be removed, or bind will failed.

exports.getFileName = function getFileName (calling_file) {
  var origPST = Error.prepareStackTrace
    , origSTL = Error.stackTraceLimit
    , dummy = {}
    , fileName

  Error.stackTraceLimit = 10

  Error.prepareStackTrace = function (e, st) {
    for (var i=0, l=st.length; i<l; i++) {
      fileName = st[i].getFileName()
      if (fileName !== __filename) {
        if (calling_file) {
            if (fileName !== calling_file) {
              return
            }
        } else {
          return
        }
      }
    }
  }

  // run the 'prepareStackTrace' function above
  Error.captureStackTrace(dummy)
  dummy.stack

 // cleanup
  Error.prepareStackTrace = origPST
  Error.stackTraceLimit = origSTL

  //In Electron, filename starts with "file://"
  var fileSchema = "file://";
  if(fileName.indexOf(fileSchema) === 0) {
     fileName = fileName.substr(fileSchema.length);
     //on windows
     if(fileName.indexOf(":/") == 2){
         fileName = fileName.substr(1);
     }
  }

  return fileName
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.