sodium-friends / sodium-native

Low level bindings for libsodium
MIT License
301 stars 66 forks source link

Electron error - Cannot Find Module #134

Closed RangerMauve closed 4 years ago

RangerMauve commented 4 years ago

I'm getting reports on Windows and Linux that folks are getting an error that says Cannot find module ...../app.asar/node_modules/sodium-native/index.js.

This doesn't seem to happen when people build from source and is only happening through automated builds on Travis in a Mac OS environment using electron-builder.

Here's a thread with the issues: https://github.com/RangerMauve/agregore-browser/issues/5#issuecomment-663985709

Seems to be originating from noise-protocol inside hypercore protocol.

I don't think I'm doing anything fancy in the setup in my travis script. It's running electron-builder build to compile the binary after an npm install.

Is there something I could look for to see why index.js wouldn't be available?

RangerMauve commented 4 years ago

Could it have something to do with caching? There's a build that runs first for running tests.

emilbayes commented 4 years ago

Not sure how this happens. We have multiple electron apps using sodium-native and noise-protocol without issue

emilbayes commented 4 years ago

I was thinking caching too, but I don’t know enough about how it works. Worth trying with the cache disabled

RangerMauve commented 4 years ago

@emilbayes Do you think you could point me to a working CI build script by any chance? 😅 I'm gonna be testing removing node_modules from my cache for my next release to see if it helps.

emilbayes commented 4 years ago

Nothing public but one thing of note is that we do have a build step with browserifg —node in there and some stuff messing with base path

RangerMauve commented 4 years ago

Ha ha, running into this again and I have no clue how I solved it before. 😂

RangerMauve commented 4 years ago

This time with webpack in the mix to make life harder for me

RangerMauve commented 4 years ago

In case someone runs into this (probably me in the future), I needed to move all the dependencies that depended on sodium-native into the app/package.json instead of /package.json in the react electron boilerplate we were using.

emilbayes commented 4 years ago

Haha thanks! Makes sense, you can’t “bundle” a native module into a single file

DougAnderson444 commented 3 years ago

you can’t “bundle” a native module into a single file

That's good to know! Would this be true for Browserify too? :thinking:

I'm wondering how we use this in the browser then :thinking:

RangerMauve commented 3 years ago

@DougAnderson444 For browsers you should be using sodium-universal that uses sodium-javascript when you're in a browser environment.