Fix for using bindings.js with eval#66
Conversation
|
@TooTallNate Could you take a look at this? |
|
@pverscha this patch still throws the |
|
Has there been any progress on this? |
I reported an error after using your bindings.js: could not find module root given file: “”.Do you have a ‘package.json’ file? at t.getRoot |
|
I had same issue. I solved it by using better-sqlite3 module. It has a nativeBinding option. This option can be used to specify file path of sqlite native .node dependency file. If this option is provided then better-sqlite3 module won't use bindings module to locate .node file so the error from bindings module doesn't occur |
Hi!
I found a lot of issues and bug reports that all seem to originate from "bindings.js" in combination with the
evalfunction. In this specific case, theexports.getFileName();returns undefined, causingexports.getRoot()to crash with the error messageCannot read property 'indexOf' of undefined at Function.getFileName (bindings.js:180)(see: #54).This PR fixes this issue by checking if a valid filename was found in
exports.getRoot()and returns undefined there if not. This, however, means that themodule_rootis set to the root-folder of your application, not thenode_modules/{package}folder of the package that's trying to find it's node-bindings. Since we've got no other information about the package root we're looking for, other than the ".node"-filename, I've added a heuristic that looks for the package name (in the node_modules-folder) that best matches the ".node"-filename.This approach seems to work very well, especially for "better-sqlite3" that suffers from this issue when used in combination with electron and web workers.
Would you be so kind to review and accept my PR?