2

When I try to build my applicaton using electron it crashes on leveldown library

Error: The module '/Users/macosx/Documents/Electron/node_modules/leveldown/build/Release/leveldown.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 64. This version of Node.js requires
NODE_MODULE_VERSION 67. Please try re-compiling or re-installing

I have tried

rm -rf node_modules/leveldown
npm install

npm rebuild leveldown--update-binary

npm uninstall leveldown

Also tried this

I had the same problem and nothing mentioned here worked for me. Here is what >worked for me:

Require all dependencies you need in the main.js file that is run by electron. (this seemed to be the first important part for me) Run npm i -D electron-rebuild to add the electron-rebuild package Remove the node-modules folder, as well as the packages-lock.json file. Run npm i to install all modules. Run ./node_modules/.bin/electron-rebuild to rebuild everything It is very important to run ./node_modules/.bin/electron-rebuild directly after npm i otherwise it did not work on my mac.

Community
  • 1
  • 1
Orlin Bobchev
  • 177
  • 1
  • 3
  • 13

1 Answers1

6

I struggled with this for a couple days. The trick is to use electron-rebuild to build the native node module, and to include the option node.__dirname = true in your webpack config, as the leveldown bindings.js depend on the __dirname global provided by Node.

Jthorpe
  • 9,756
  • 2
  • 49
  • 64
  • Thank you very much for this response, but can you elaborate on this, did you only run electron-rebuild or manually added node.__dirname ? – Orlin Bobchev Jul 29 '19 at 12:37
  • This answer assumes that you're build routine is using webpack, and if so, you should have some files such as `webpack.base.config.js` which contain the parameters used by webpack for the build. In these files, there will be a `node` section, and you need to set the value of `_dirname` to `true` in that nested object. Once you've done that, when you re-run electron-rebuild, it should have the correctly defined (ambient) `__dirname` variable which is required by the leveldown build process. – Jthorpe Jul 29 '19 at 17:44
  • Thank you for the __dirname trick!!!!! Thank you thank you thank you! – CamHart Jul 07 '20 at 23:06
  • OMG you saved my life, I have been searching the darkest corners of the web for hours to find the solution! – djfm Feb 07 '22 at 21:33