Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
I found a lot of issues and bug reports that all seem to originate from "bindings.js" in combination with the
eval
function. 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_root
is 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?