Description
This is similar to #866 & #126
When webpacking (or in my case Rollup) and then the "bindings.js" attempts to look in the completely wrong location. I have found a hack that I think might be a better feature in the better-sqlite than me manually adding the code to the better-sqlite.
So here is the issue, I have the better_sqlite3.node copied to an extracted location in my electron application, however rollup (& webpack) replaces the "require" with their own require making it impossible for me to use the nativeBinding
to point to it because a require just uses the replaced call. However, if replace
better-sqlite3/lib/database.js
Lines 49 to 51 in 37b7714
the call inside the lib/database file with:
const create = nodeModule.createRequire || nodeModule.createRequireFromPath;
const requireMe = create( require("node:url").pathToFileURL(__filename).href );
addon = requireMe(path.resolve(nativeBindingPath).replace(/(\.node)?$/, '.node'));
Then I can create my own "require" call that actually calls the normal node/electron require statement. (Webpack has I believe a __non_webpack_require__
(I think it is called this) function which is the way you can access it in webpack). And you can also sometimes get access to it via global.require, etc...
Now the feature idea or request is to allow me to pass in the require
function call you will use for the nativeBinding
OR to allow me to manually load the binding myself and pass it in, so that you can just use it.