mymonero / mymonero-core-js

The JS library containing the Monero crypto plus lightwallet functions behind the official MyMonero apps
BSD 3-Clause "New" or "Revised" License
101 stars 103 forks source link

MyMoneroCoreBridge/locateFile() on node.js didn't find "monero_utils" after bundling with webpack. #100

Open babel5405 opened 4 years ago

babel5405 commented 4 years ago

I'm importing mymonero-core-js wiith a standard require() in the main thread of my electron application and everything has been working for a while but I recently added my main.js to my webpack bundle and it's created some issues.

Liine 58 of MyMoneroCoreBridge.js is returning the file the bundle is in, instead of the expected monero_utils, which is causing the block below to move onto it's else, rendering everything non-functional.

if (lastPathComponent == "monero_utils") { // typical node or electron-main process
    fullPath = path.format({
        dir: this_scriptDirectory,
        base: filename
    })
} else {
    console.warn('MyMoneroCoreBridge/locateFile() on node.js didn't find "monero_utils" (or possibly MyMoneroCoreBridge.js) itself in the expected location in the following path. The function may need to be expanded but it might in normal situations be likely to be another bug. ${pathTo_cryptonoteUtilsDir}')
}

(Note, I modified the code above slightly so it could be enclosed completely in a code block for the issue. Just replaced the backtick's with single quotes.)

What can I do to correct the path it's receiving so it gets what it actually needs? I'm assuming there's a reason it expects to be ran from monero_utils, but is there any way to work around that?

babel5405 commented 4 years ago

II'm fairly certain I should be able to exclude the module from webpack and include it separately in the bundle, but ideally I'd still like to be able to pack it with the rest of the main entry point.

babel5405 commented 4 years ago

I would like to see if the developers have a better solution, but I went ahead and implemented an exclusion in webpack and it's resolved the issue (though this means the module isn't bundled.)

externals: [
        function(context, request, callback) {
            if (/^mymonero-core-js$/.test(request)) {
                return callback(null, 'commonjs ' + request);
            }
            callback();
        }
    ]