3
votes

Please help me to understand how to rebuild the native npm modules for Electron 1.6.2?

I used steps from https://electron.atom.io/docs/tutorial/quick-start to create a simple Electron application.
Then I installed ref package and loaded it in main.js.
ref package - it is the native package. I have to rebuild this package to have ability to use it in the Electron application.

I used following tutorial to rebuild the native package - https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md

There are 3 approaches how to rebuild the native npm packages:

1) "Installing modules and rebuilding for Electron using electron-rebuild":
I installed electron-rebuild npm package.
Then, according to tutorial, I need just to run following command:
.\node_modules.bin\electron-rebuild.cmd
But electron-rebuild tried to download https://atom.io/download/electron/v1.6.2/iojs-v1.6.2.tar.gz
Why it downloaded something from https://atom.io/download/electron if Electron release files are located here - https://github.com/electron/electron/releases?
Electron 1.6.2 was released only few weeks ago, but iojs-v1.6.2.tar.gz was released in Mar 2015.
Do I understand correctly that electron-rebuild downloads the wrong files?

2) Manually building packages for Electron using node-gyp.
set HOME=%USERPROFILE%/.electron-gyp
cd ./node_modules/ref
node-gyp rebuild --target=1.6.2 --arch=x64 --dist-url=https://atom.io/download/electron

And here again dist-url uses https://atom.io/download/electron.
Why?
I tried do not use --dist-url.
But in this case node-gyp downloads following files:
gyp http GET https://iojs.org/download/release/v1.6.2/iojs-v1.6.2.tar.gz
gyp http 200 https://iojs.org/download/release/v1.6.2/iojs-v1.6.2.tar.gz
gyp http GET https://iojs.org/download/release/v1.6.2/SHASUMS256.txt
gyp http GET https://iojs.org/download/release/v1.6.2/win-x64/iojs.lib
gyp http GET https://iojs.org/download/release/v1.6.2/win-x86/iojs.lib
gyp http 200 https://iojs.org/download/release/v1.6.2/SHASUMS256.txt
gyp http 200 https://iojs.org/download/release/v1.6.2/win-x64/iojs.lib
gyp http 200 https://iojs.org/download/release/v1.6.2/win-x86/iojs.lib
Is it correct?

3) Rebuild native packages using npm:
rem # Electron's version.
set npm_config_target=1.6.2
rem # The architecture of Electron, can be ia32 or x64.
set npm_config_arch=x64
set npm_config_target_arch=x64
rem # Download headers for Electron.
rem set npm_config_disturl=https://atom.io/download/electron
rem # Tell node-pre-gyp that we are building for Electron.
set npm_config_runtime=electron
rem # Tell node-pre-gyp to build module from source code.
set npm_config_build_from_source=true
rem # Install all dependencies, and store cache to ~/.electron-gyp.
set HOME=%USERPROFILE.electron-gyp
npm install

Again https://atom.io/download/electron.
Why?

Does anyone know how to rebuild ref native package for Electron 1.6.2 correctly?

1
There is no problem here, the dist URL is correct. It is where the releases are mirrored / hostedMarshallOfSound
@MarshallOfSound I do not understand. Electron 1.6.2 was released 15 days ago. iojs.org/download/release/v1.6.2/iojs-v1.6.2.tar.gz was created 2 years ago - 23-Mar-2015. Why does electron-rebuild use very old iojs-v1.6.2.tar.gz to rebuild the native npm package with new Electron 1.6.2?Volodymyr Bezuglyy
It doesn't, due to the way legacy build systems work any node versions between 1 and 3 in this case 1.6.2 is considered to be iojs. This is how node-gyp was written and therefore electron name there files in a way that makes it workMarshallOfSound
@MarshallOfSound Why version of node? According to the tutorial I should specify the version of Electron. See github.com/electron/electron/blob/master/docs/tutorial/… # Electron's version. export npm_config_target=1.2.3 ... The --target=1.2.3 is version of Electron. ... electron-rebuild --help Usage: electron-rebuild --version [version] --module-dir [path] Options: -v, --version The version of Electron to build againstVolodymyr Bezuglyy
This is correct, it's important to remember however that internally Electron uses node and therefore all build tools that target node things, like node-gyp are effectively being tricked into thinking Electron is nodejs. In this scenario we are telling node-gyp rebuild this native node module using nodejs headers from this URL and for this version of Electron. The version is only used to fetch the correct header files nothing more. I'm not sure what your actual question is as all examples you provided are from the docs and are correctMarshallOfSound

1 Answers

1
votes

You are correct, the version given to node-gyp maps to the Electron version not the internal node version as that is the version where the headers are uploaded to. There is actually a more complex explanation behind all this but it shouldn't matter to the end user. The code you provided is correct and from the docs. It works. No need to understand the inner workings of why.