Electron: __ was compiled against a different version of Node.js

2.8k views Asked by At

When trying to package electron app on macOS Sierra using electron-installer-dmg, I get the following:

Error: The module '/Users/august/projects/node_modules/macos-alias/build/Release/volume.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 54. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at Object.Module._extensions..node (module.js:598:18)<br>
at Module.load (module.js:503:32)<br>
at tryModuleLoad (module.js:466:12)<br>
at Function.Module._load (module.js:458:3)<br>
at Module.require (module.js:513:17)<br>
at require (internal/module.js:11:18)<br>
at Object.<anonymous> (/Users/august/projects/node_modules/macos-alias/lib/create.js:7:13)<br>
at Module._compile (module.js:569:30)<br>
at Object.Module._extensions..js (module.js:580:10)<br>
at Module.load (module.js:503:32)<br>

Versions:

Node 8.0.0
npm: 5.4
electron: 1.7.5
electron-installer-dmg: 0.2.1
electron-packager: 8.7.2
macos-alias: 0

I've tried:

  • Switching node versions.
  • Running ./node_modules/.bin/electron-rebuild
  • Removing node_modules and running npm install
  • Running npm cache clear and the re-installing packages
  • Running npm rebuild
  • Setting .npmrc file:

    runtime = electron
    target = 1.7.5
    target_arch = x64
    disturl = https://atom.io/download/atom-shell
    

Is there any solution to this problem?

2

There are 2 answers

3
Sotiris Kiritsis On

Electron 1.7.5 uses:

  • Node: 7.9.0
  • Chromium: 58.0.3029.110
  • V8: 5.8.283.38

Only packages compiled with the same version of Node will work. Try downgrading your Node version to 7.9 (you can find the installer here) and try the whole process from the start.

0
Long Nguyen On

If you are using electron-builder to build your electron project. You need to run this command electron-builder install-app-deps

Add this command into scripts of package.json to ensure your native dependencies are always matched electron version.

{
    "scripts": {
       "postinstall": "electron-builder install-app-deps",
    }
}