Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

NODE_MODULE_VERSION problems with electron 1.7.6 #77

Closed
jflitton opened this issue Sep 24, 2017 · 18 comments
Closed

NODE_MODULE_VERSION problems with electron 1.7.6 #77

jflitton opened this issue Sep 24, 2017 · 18 comments
Labels
electron-rebuild Issues related to how keytar is compiled in a project that also uses electron-rebuild

Comments

@jflitton
Copy link

jflitton commented Sep 24, 2017

I'm using node version 7.10.0, electron 1.7.6 and macOS. When running

const keytar = remote.require('keytar')

the following error occurs

The module '/Volumes/Code/dynamodb-workbench/dist/node_modules/keytar/build/Release/keytar.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 54. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or`npm install`).

Things I've tried:

  • Deleting/re-installing all modules
  • Switching to Node 8.4.0
  • ./node_modules/.bin/electron-rebuild
  • Using the script defined here

Any idea what's going on here? I would've expected one of the three ways to get native modules to work would do the trick.

@jflitton
Copy link
Author

jflitton commented Sep 27, 2017

Also can reproduce with electron-forge:

electron-forge init test-project
cd test-project
npm install keytar --save

add the following to index.html:

<script>
    import {remote} from 'electron'
    const keytar = remote.require('keytar')
</script>
npm start

On load I get the following error in the console:

Uncaught Error: The module '/Volumes/Code/test-project/node_modules/keytar/build/Release/keytar.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 48. This version of Node.js requires
NODE_MODULE_VERSION 54. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or`npm install`).
Error: The module '/Volumes/Code/test-project/node_modules/keytar/build/Release/keytar.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 48. This version of Node.js requires
NODE_MODULE_VERSION 54. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or`npm install`).
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Volumes/Code/test-project/node_modules/keytar/lib/keytar.js:1:169)
    at Object.<anonymous> (/Volumes/Code/test-project/node_modules/keytar/lib/keytar.js:55:3)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Volumes/Code/test-project/node_modules/keytar/lib/keytar.js:1:169)
    at Object.<anonymous> (/Volumes/Code/test-project/node_modules/keytar/lib/keytar.js:55:3)
    at metaToValue (/Volumes/Code/test-project/node_modules/electron-prebuilt-compile/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/api/remote.js:234:13)
    at Object.exports.require (/Volumes/Code/test-project/node_modules/electron-prebuilt-compile/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/api/remote.js:313:10)
    at file:///Volumes/Code/test-project/src/index.html:14:33

Still using macOS and node 8.4.0

@ecnepsnai
Copy link

I'm also having this problem on both node 6.11.4 and 8.6.0 (tried both)

@s4m2d
Copy link

s4m2d commented Oct 10, 2017

Having the same issue with node 8.2.1 and electron 1.7.8 (think this is an electron / electron-rebuild problem. Electron uses a different version of NodeJs than your environment.)
have a look at: https://github.com/electron/electron-rebuild
electron and node-hid; using electron-rebuild, but getting:
(For me rebuild only works as script named "postinstall", not tested yet)

Uncaught Exception:
Error: The module '/Users/samvieten/dev/mwad3/app/node_modules/xbox-controller/node_modules/node-hid/build/Release/HID.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 54. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or`npm install`).
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/samvieten/dev/mwad3/app/node_modules/xbox-controller/node_modules/node-hid/index.js:5:15)
    at Object.<anonymous> (/Users/samvieten/dev/mwad3/app/node_modules/xbox-controller/node_modules/node-hid/index.js:94:3)

@EricRabil
Copy link

EricRabil commented Oct 16, 2017

This sounds like more of an electron problem than a node-keytar problem

@gagarin55
Copy link

I can't find 54 version at https://nodejs.org/en/download/releases/, any suggestions ?

@s4m2d
Copy link

s4m2d commented Oct 21, 2017

It's the module version, think it's used in Node v. 7.0.0 (just a guess)

@benjcresswell
Copy link

We had the same problem but got around it by ensuring that ./node_modules/.bin/electron-rebuild is run directly after any npm install on our macs

@ruankotovich
Copy link

I'm having the same problem as OP (the exact version by the way)

I am using nvm to downgrade my env node version to the exact current Electron node version, also, I am using electron-rebuild in order to try rebuild the imported module.

The native module is mine and compiled by my own.

I've tried to follow this tutorial but the error keeps going on, and I dunno how to do.

@bwheeler96
Copy link

./node_modules/.bin/electron-rebuild

^ This worked for me

@ddombrowsky
Copy link

same problem with node-usb

App threw an error during load
Error: The module 'node_modules/usb/src/binding/usb_bindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 48. This version of Node.js requires
NODE_MODULE_VERSION 54. Please try re-compiling or re-installing

I installed the rebuild tool using npm install electron-rebuild and ran ./node_modules/.bin/electron-rebuild. Seemed to work. Wish I knew what the root cause was, though.

@Acika00mk
Copy link

HI,
had the same issue,
and i fixed it with

"electron": "^1.8.2",
"keytar-prebuild": "^4.1.1",
"electron-rebuild": "^1.7.3",
node version  : 8.9.4

Include in the main.ts/main.js file
const keytar = require('keytar-prebuild');
Remove node_modules folder and package-lock.json.
Do normal npm install then ./node_modules/.bin/electron-rebuild.
If you want you can try to package it to an app, it will work. Tested.

@iamyohann
Copy link

@Acika00mk also remember to rebuild dev dependencies as electron-rebuild only does prod and optional dependencies by default.

Use this instead for devDependencies as well
./node_modules/.bin/electron-rebuild -p -t "dev,prod,optional"

-p for parallel

@denigada
Copy link

denigada commented Apr 4, 2018

I am having the same issue with nwjs, could not find a working solution

@adeperio
Copy link

adeperio commented May 2, 2018

@bwheeler96 's solution worked for me to

  1. Install electron-rebuild: npm install --save-dev electron-rebuild
  2. Run $(npm bin)/electron-rebuild to build binaries for the right version of node
  3. Add "$(npm bin)/electron-rebuild" in my package.json scripts

Followed the instructions on https://github.com/electron/electron-rebuild "How does it work?"

@beauallison
Copy link

beauallison commented Jun 26, 2018

Passing the target version number using the -v arg worked for me.

Note: this is the Electron version, not the Node version.

Eg ./node_modules/.bin/electron-rebuild -v 1.7.12

@moki298
Copy link

moki298 commented Aug 28, 2018

I faced the same issue with grpc module and in my case, I was using electron and have set a wrong electron version in the env variable "export npm_config_target=1.2.3", setting it to the electron version I am using resolved the issue on my end. Hope this helps someone who set env variables as given here (https://electronjs.org/docs/tutorial/using-native-node-modules#the-npm-way)

@shiftkey shiftkey added the electron-rebuild Issues related to how keytar is compiled in a project that also uses electron-rebuild label Jan 21, 2019
@LukeTurp
Copy link

LukeTurp commented May 2, 2019

I had this same issue with a different library. I came accross this issue, and @benjcresswell 's solution worked for me, but I was on Windows - so I ran:
.\node_modules\.bin\electron-rebuild.cmd
Thanks to everyone's efforts to resolve this.

@shiftkey
Copy link
Contributor

Closing this out because building native modules correctly is outside the scope of keytar, and the Electron docs are what I recommend reading to get your environment setup.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
electron-rebuild Issues related to how keytar is compiled in a project that also uses electron-rebuild
Projects
None yet
Development

No branches or pull requests