How to rebuild native npm modules for Electron?


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

I used steps from 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 -

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:
    But electron-rebuild tried to download
    Why it downloaded something from if Electron release files are located here -
    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=

And here again dist-url uses
I tried do not use --dist-url.
But in this case node-gyp downloads following files:
gyp http GET
gyp http 200
gyp http GET
gyp http GET
gyp http GET
gyp http 200
gyp http 200
gyp http 200
Is it correct?

  1. 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=
    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


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


No, electron-rebuild downloads the correct files, I forget why they’re named iojs but it doesn’t really matter.


I do not understand.
Electron 1.6.2 was released only 15 days ago. 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?


According to the tutorial I should specify the version of Electron, not Node.

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]
-v, --version The version of Electron to build against

Why does electron-builder/node-gyp uses version of Electron as version of Node?


Ok, now I understand that electron-rebuild really uses old iojs-v1.6.2.tar.gz to rebuild native packages for new Electron.
I can rebuild ref package for x64 architecture and use it in my Electron application.
cd .\node_modules\ref
"D:\tools\nodejs\node.exe" “C:\tmp\test\node_modules\node-gyp\bin\node-gyp.js” “rebuild” “–target=1.6.1” “–arch=x64” “–build-from-source” --nodedir=D:\tools\iojs-v1.6.1
And it works.

But when I try to rebuild ref package for 3b bit architecture and set --arch=ia32 then Electron cannot start and complains that “Error: %1 is not a valid Win32 application”.

What could be the problem?