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

Detect the correct runtime when find() is called from Electron #187

Merged
merged 1 commit into from
Mar 31, 2016

Conversation

enlight
Copy link
Contributor

@enlight enlight commented Nov 5, 2015

This fixes the case where require('node-pre-gyp').find() is called from Electron without explicitly specifying the runtime in the options. Previously the runtime would just default to "node" and find() would fail to find any native modules specifically built for Electron because node-gyp named the build output directory {runtime}-v{version}-{platform}-{arch}. For example after building a native module for Electron v0.34.2 the module binary ended up in the electron-v0.34-win32-x64 directory, but find() was looking for it in the node-v46-win32-x64 directory.

@enlight
Copy link
Contributor Author

enlight commented Nov 5, 2015

There's actually an existing PR #177 to address this issue, unfortunately I only noticed it after implementing my own fix. Compared to the previous PR mine is a single commit and more conformant to the existing code style. Anyway, I'm not fussed about which one gets merged in as long as the issue is fixed.

@ajusa
Copy link

ajusa commented Nov 14, 2015

Can someone merge this? I need this for my latest project...

@maxkorp
Copy link

maxkorp commented Dec 2, 2015

  1. These test failures seem to strictly be CI hiccups with network connectivity or missing fixtures, not problems with the code/modification.

  2. I made an additional module to sort of support this, until things start getting merged at least. It doesnt look at process versions but instead at config from an npmrc, although process.versions could be easily added as well.

https://github.com/maxkorp/node-pre-gyp-npmrc-helper

Ideally, I'd like to get the npm config lookup and 187 added to just node-pre-gyp.

This fixes the case where require('node-pre-gyp').find() is called
from Electron without explicitly specifying the runtime in the options.
Previously the runtime would just default to "node" and find() would
fail to find any native modules specifically built for Electron because
`node-gyp` named the build output directory
`{runtime}-v{version}-{platform}-{arch}`. For example after building
a native module for Electron v0.34.2 the module binary ended up in the
`electron-v0.34-win32-x64` directory, but find() was looking for it in
the `node-v46-win32-x64` directory.
@lukeapage
Copy link

I can confirm this branch works. Please merge!

@lukeapage
Copy link

@springmeyer any chance you can take a look ?

@enlight
Copy link
Contributor Author

enlight commented Jan 27, 2016

To anyone else who stumbles in here I've created electron-node-pre-gyp-fix to monkey-patch node-pre-gyp at runtime, some may find it preferable to relying on the branch in this PR.

enlight added a commit to debugworkbench/hydragon that referenced this pull request Feb 2, 2016
The workaround consists of copying the built native modules to the
directory where `node-pre-gyp` looks for them at runtime. This seems
to be the only way to get `node-inspector` working properly because my
attempts to monkey-patch `node-pre-gyp` seem to fail in that case
(even thought monkey-patching worked for other native modules like
`sqlite3`). This workaround can be removed if
mapbox/node-pre-gyp#187 is ever merged in.
@enlight
Copy link
Contributor Author

enlight commented Feb 2, 2016

Actually, the node-pre-gyp workaround implemented in electron-rebuild is more robust than my monkey-patch, the monkey-patch doesn't seem to work on node-inspector.

@maxkorp
Copy link

maxkorp commented Feb 3, 2016

For what its worth, with the current version, just using an npmrc with the appropriate target and versions set will suffice for npm install to download the appropriate binaries, or compile appropriately when needed.

@barbalex
Copy link

please merge this

@springmeyer
Copy link
Contributor

Actually, the node-pre-gyp workaround implemented in electron-rebuild is more robust than my monkey-patch, the monkey-patch doesn't seem to work on node-inspector.

This patch looks good and mergable but I held back due to the above comment. @enlight - can you share more details on whether you think this should land or not?

@lukeapage
Copy link

@springmeyer that comment is specific to electron-rebuild and what they are doing - i dont think it is a criticism of this patch. Currently electrons primary instructions for how to debug include installing a patched version of node-pre-gyp - http://electron.atom.io/docs/v0.37.3/tutorial/debugging-main-process/

@enlight
Copy link
Contributor Author

enlight commented Mar 30, 2016

@lukeapage is correct @springmeyer my earlier comment was in relation to one of the workarounds people have had to employ while waiting for this PR to get merged, once this PR is merged those workarounds will no longer be necessary.

@springmeyer
Copy link
Contributor

Thanks @enlight - I'll merge and tag v0.6.25 now with this fix. Thanks!

@springmeyer springmeyer merged commit 2c71565 into mapbox:master Mar 31, 2016
@barbalex
Copy link

Yuppi aye, aye, yuppi yuppi aye...

Thanks a lot to all!

@hedefalk
Copy link

This did not work for apm, but looking at this commit I tested just setting --runtime=electron and all my troubles was gone. Made a PR for apm: atom/apm#536

@Steviey
Copy link

Steviey commented Sep 13, 2016

module.js:442 Uncaught Error: Cannot find module
...sqlite3\lib\binding\electron-v1.3-win32-x64\node_sqlite3.node'

...seems to be related and not fixed.

  • Win 7
    npm ERR! node v4.5.0
    npm ERR! npm v2.15.9
    Electron 1.3.5

@chrisveness
Copy link

Hmm... have I hit the same (or similar) problem?

Uncaught Exception: Error: Cannot find module '.../app/node_modules/sqlite3/lib/binding/electron-v1.4-linux-x64/node_sqlite3.node'
  at Module._resolveFilename (module.js:455:15)

Noob on Electron trying to find my way around, not sure where node-pre-gyp fits in, hitting problems with sqlite3...

Using Electron 'two package.json', Electron v1.4.1, node-pre-gyp v0.6.28 from sqlite3 v3.1.4, node v6.6.0, npm v3.10.3 on Linux.

Any hints what do to?

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

Successfully merging this pull request may close these issues.

None yet

9 participants