Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module mismatch following readme instructions #23

Open
abulka opened this issue Mar 23, 2018 · 4 comments
Open

Module mismatch following readme instructions #23

abulka opened this issue Mar 23, 2018 · 4 comments

Comments

@abulka
Copy link

abulka commented Mar 23, 2018

Following the recommended readme instructions, where package.json contains:

  "devDependencies": {
    "electron": "^1.7.6",
    "electron-packager": "^9.0.1"
  }

results in a javascript error

The module '/Users/Me/Devel/electron-python-example/node_modules/zeromq/build/Release/zmq.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 process.module.(anonymous function) [as dlopen] 

because specifying "electron": "^1.7.6", these days (2018) will cause npm to actually pick up electron 1.8.4 - which won't work with your custom zerorpc version.

This is because the ^ symbol in package.json means the latest available 1.* version of electron is searched for and installed, see npm versioning.

I finally got the example to work by removing the ^

  "devDependencies": {
    "electron": "1.7.6",
    "electron-packager": "9.0.1"
  }

thus causing that exact version of electron to be installed, which matches your 'prebuilt' zerorpc dependency "zerorpc": "git+https://github.com/fyears/zerorpc-node.git".

I believe that the readme should be updated to remove the ^ from package.json to help users avoid this problem.

@abulka
Copy link
Author

abulka commented Mar 25, 2018

Turns out that the module mismatch problem can be fixed by installing electron-rebuild

npm install --save-dev electron-rebuild

and running it after npm install. This step's purpose is to rebuild native Node.js modules against the version of Node.js that your Electron project is using. Remember that electron comes with its own internal version of node. The rebuild step will rebuild the node module zerorpc from fyear's custom repository to work with whatever version of electron happens to get installed when you npm install.

# install dependencies  based on the package.json first
npm install

#every time you run 'npm install',you have to run this:
./node_modules/.bin/electron-rebuild

# run
./node_modules/.bin/electron .

This means we don't need to remove the ^ from package.json. Whatever version of electron is installed, the rebuild step will repair any module mismatch issues.

@jafermarq
Copy link

jafermarq commented Apr 2, 2018

@abulka, thanks for the above. Did you manage to pack the application? I manage to compile it ok, but still, have the same error when running the generated executable(MODULE_VERSION...). I tried adding the argument --electron-version=1.7.6 to electron-packager but didn't solve it.

I run this bash script to do the whole thing at once:

rm -rf ~/.node-gyp
rm -rf ~/.electron-gyp
rm -rf ./node_modules

npm install --save-dev electron-rebuild

# install dependencies  based on the package.json first
npm install --runtime=electron --target=1.7.6

#every time you run 'npm install',you have to run this:
./node_modules/.bin/electron-rebuild

# run (works great)
./node_modules/.bin/electron .


# Build python app
pyinstaller pycalc/api.py --distpath pycalcdist

rm -rf build/
rm -rf api.spec

# build Electron app
./node_modules/.bin/electron-packager .  --electron-version=1.7.6 --overwrite --ignore="pycalc$" --ignore="\.venv" --ignore="old-post-backup"

@yeshymanoharan
Copy link

yeshymanoharan commented Apr 18, 2018

I am also running into the error @jafermarq pointed out. Specifically, I'm getting the error
cannot find module 'zerorpc' in the chromium console once i try to launch the app. I'm thinking that electron-rebuild has to be integrated with electron-packager, which is documented on the electron-rebuild github page.

@yeshymanoharan
Copy link

yeshymanoharan commented Apr 18, 2018

ok @jafermarq I found the error.

When you use the electron packager, change the '--electron-version' tag to the version of electron that packages are being rebuild to (1.8.4). And make sure that all of the node modules are being included by using the '--no-prune' flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants