Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why skip monkey patching when electron method in stack? #2

Open
markgillnz opened this issue Sep 20, 2017 · 4 comments
Open

Why skip monkey patching when electron method in stack? #2

markgillnz opened this issue Sep 20, 2017 · 4 comments
Assignees

Comments

@markgillnz
Copy link

There is a comment as below that skips monkey patching when an electron method is in the callstack but no reasoning behind this decision.
/* Skip monkey patching when an electron method is in the callstack. */

Can you explain why you skip patching in this case as it means sqlite3 cannot be used within Electron with asar enabled and sqlite3 unpacked.

Error I am seeing:
{ Error: Cannot find module 'C:\Users\FlyingSquad\AppData\Local\EMRConnect\app-1.4.0\resources\app.asar\node_modules\sqlite3\lib\binding\electron-v1.4-win32-ia32\node_sqlite3.node' at Module._resolveFilename (module.js:455:15) at Function.Module._resolveFilename (C:\Users\FlyingSquad\AppData\Local\EMRConnect\app-1.4.0\resources\electron.asar\common\reset-search-paths.js:35:12) at Function.Module._load (module.js:403:25) at Module.require (module.js:483:17) at require (internal/module.js:20:19) at Object.<anonymous> (C:\Users\FlyingSquad\AppData\Local\EMRConnect\app-1.4.0\resources\app.asar\node_modules\sqlite3\lib\sqlite3.js:6:15) at Module._compile (module.js:556:32) at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) code: 'MODULE_NOT_FOUND' }

@Skywalker13
Copy link
Member

Skywalker13 commented Sep 21, 2017

IIRC, it skips in the case where the caller is in ELECTRON_ASAR or electron.asar because child_process.spawn/exec is already aware of asar.unpack dir. Patching here breaks the node spawner.

And your error seems elsewhere.

Error: Cannot find module 'C:\Users\FlyingSquad\AppData\Local\EMRConnect\app-1.4.0\resources\app.asar\node_modules\sqlite3\lib\binding\electron-v1.4-win32-ia32\node_sqlite3.node'

node_sqlite3.node is a binary, not a node module. It doesn't make sense.

child_process API must be used here. I don't understand.. or maybe it's just because require('node-pre-gyp').find is already doing strange things with require().

Can you provide a sample please?

@Skywalker13
Copy link
Member

Skywalker13 commented Sep 21, 2017

OK; I think that now I understand. I never played with native addons and require supports binary files. https://nodejs.org/api/modules.html#modules_file_modules

But even in this case, it should work. I think that the problem is around the lines 310 and 313 of node-pre-gyp. https://github.com/mapbox/node-pre-gyp/blob/master/lib/util/versioning.js#L310
According to the comments, it's using relative paths (and with hazardous it's a problem). I must investigate step by step by debugging this stuff.

@Skywalker13
Copy link
Member

@markgillnz Have you tried without unpacking sqlite3? It should work because nothing is spawned.

@markgillnz
Copy link
Author

@Skywalker13 yes. Originally I did not have sqlite3 unpacked and got the error in my first post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants