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

Problems with native modules #39

Closed
timbod7 opened this issue Oct 6, 2015 · 19 comments
Closed

Problems with native modules #39

timbod7 opened this issue Oct 6, 2015 · 19 comments
Assignees
Labels
Milestone

Comments

@timbod7
Copy link

@timbod7 timbod7 commented Oct 6, 2015

My workflow for an electron app is

# Install all dependencies, including native modules
npm install

# Ensure native modules are built to match electron
./node_modules/.bin/electron-rebuild

# Test the app
./node_modules/.bin/electron .

# package the app
./node_modules/.bin/electron-packager . \"MyApp\" --out=dist/osx --platform=darwin --arch=x64 --version=0.33.6  --icon=assets/osx/myicon.icn

# build a distribution
./node_modules/.bin/electron-builder \"dist/osx/MyApp-darwin-x64/MyApp.app\" --platform=osx --out=\"dist/osx\" --config=packager.json"

The last step is failing with the following error:

- Starting build for ´osx´ - 
Writing temporary ´appdmg.json´
Wrote temporary ´appdmg.json´
Kicking off ´appdmg´
module.js:355
  Module._extensions[extension](this, filename);
                               ^
Error: Module version mismatch. Expected 14, got 46.
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/xxx/projects/myapp/myapp/electron/node_modules/electron-builder/node_modules/appdmg/node_modules/ds-store/node_modules/macos-alias/lib/create.js:7:13)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

I believe this is happening because the electron-builder script is running using a node implementation incompatible with electron (which is why the electron-rebuild script is necessary):

$ npm --version
2.5.1
$ node --version
v0.12.0
$ ./node_modules/.bin/electron --version
v0.33.6

Is this a bug? What is the recommended way to build build distributions with native modules?

@stefanjudis
Copy link
Member

@stefanjudis stefanjudis commented Oct 6, 2015

@timbod7 Hmm that's interesting.

I haven't had this problem yet.

So according to your assumption running electron-builder with the same node version electron ships should solve the problem, correct?

Can we confirm that, maybe using nvmor something?

@timbod7
Copy link
Author

@timbod7 timbod7 commented Oct 6, 2015

Yes. I can confirm that running electron-builder with the matching node version works ok. nvm was a good suggestion - I'm new to the node js world and wasn't aware of it. If I use it to select the correct version first, and drop the electron-rebuild step, everything works ok, ie:

# Install and select node and npm version to match electron
nvm install v4.1.1

# Install all dependencies, including native modules
npm install

# Test the app
./node_modules/.bin/electron .

# package the app
./node_modules/.bin/electron-packager . \"MyApp\" --out=dist/osx --platform=darwin --arch=x64 --version=0.33.6  --icon=assets/osx/myicon.icn

# build a distribution
./node_modules/.bin/electron-builder \"dist/osx/MyApp-darwin-x64/MyApp.app\" --platform=osx --out=\"dist/osx\" --config=packager.json"
@stefanjudis
Copy link
Member

@stefanjudis stefanjudis commented Oct 6, 2015

@timbod7

Cool - glad we found at least a temporary solution. :bowtie:

I'm really interested in digging a bit more into this problem - might take some time, but I'd love to solve this for future cases. :)

Can not promise it happens quickly. So you're okay with nvm setup for now?

Any help researching and debugging here is also more than welcome.

@timbod7
Copy link
Author

@timbod7 timbod7 commented Oct 6, 2015

Yes - happy with the nvm solution for now. Thanks for your help on this.

@stefanjudis
Copy link
Member

@stefanjudis stefanjudis commented Oct 6, 2015

Anytime. :)

@develar
Copy link
Member

@develar develar commented Feb 20, 2016

Please use two-package.json layout to avoid electron-rebuild usage. In 2.8 we support native dependencies compilation, see not yet commited docs. More detailed docs will be soon.

@develar develar closed this Feb 20, 2016
@develar develar added this to the v2.8.0 milestone Feb 20, 2016
@develar develar self-assigned this Feb 20, 2016
@ccnokes
Copy link

@ccnokes ccnokes commented Feb 25, 2016

@develar Could you please explain why the two package.json structure is ideal and how it enables support for native modules?

I'm currently trying to require a native module and it throws errors about "bindings not found".

@develar
Copy link
Member

@develar develar commented Feb 25, 2016

@ccnokes It is a common practice, please see https://github.com/szwacz/electron-boilerplate#omg-but-seriously-why-there-are-two-packagejson In our readme there is a link to real world project.

And yes, we (at least, I) are not going to fight against 2 mentioned critical issues — just use two package.json structure because otherwise it will be constant battle.

@ccnokes
Copy link

@ccnokes ccnokes commented Feb 25, 2016

@develar Thanks, I got it working!

@akdiallo
Copy link

@akdiallo akdiallo commented Mar 18, 2016

@ccnokes What did you do to make it work ? I'm having this issue :
$ nvm install v4.4.0
-bash: nvm: command not found

My version of node : v4.4.0
My version of npm : 2.14.20

I'm trying to make an installer in Mac OSX yosemite for Windows.

I run this command : npm run dist (based on this link : https://github.com/loopline-systems/electron-builder

Thanks in advance

@develar
Copy link
Member

@develar develar commented Mar 18, 2016

@akdiallo nvm here only as an example tool to install custom version of nodejs. Nothing more. Just use two-package.json project structure and forget about native modules problem.

electron-builder will rebuild native modules under the hood and you don't need to worry about it.

@ccnokes
Copy link

@ccnokes ccnokes commented Mar 18, 2016

@akdiallo ditto to what @develar said. But just in case you need more context, nvm stands for node version manager and simply allows you to run multiple version of node on the same machine, see https://github.com/creationix/nvm.

@akdiallo
Copy link

@akdiallo akdiallo commented Mar 18, 2016

@ccnokes @develar Thank you for your quick answer. That's what I'm doing and now i'm getting errors with makensis.

When I run this command : electron-builder dist/win32/app-win32-x64/ --platform=win --out=dist/ --config=packager.json

I have these errors :

makensis:  - nsProcess::_FindProcess
 - nsProcess::_KillProcess
 - nsProcess::_Unload
Error while loading icon from "icon.ico": invalid icon file

makensis: Error in macro MUI_INTERFACE on macroline 64
Error in macro MUI_PAGE_INIT on macroline 3
Error in macro MUI_PAGE_WELCOME on macroline 5
Error in script "/var/folders/fr/bm6r9_h52x5516gqfw4c4x2r0000gn/T/vwuvgt0ww4ggw8ow88ok.tpl" on line 29 -- aborting creation process

Finished makensis with code 1
/Users/khadre/.nvm/versions/node/v4.1.1/lib/node_modules/electron-builder/cli.js:63
    throw error;
    ^

Error: makensis failed
    at ChildProcess.<anonymous> (/Users/khadre/.nvm/versions/node/v4.1.1/lib/node_modules/electron-builder/lib/win.js:103:28)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:817:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at Pipe._onclose (net.js:469:12)

@akdiallo
Copy link

@akdiallo akdiallo commented Mar 19, 2016

Finally found where the problem was coming from . My .ico file wasn't good. It was 48x48 size when it should have been 256x256 . Moreover, I didn't put all of my resources in the build folder as specified in the electron-builder github page.
Once done that, I tested the install wizard in Windows 10 and it's working. But the app still cannot execute itself. Will keep you posted, I suspect it's related to the platform parameter (win32) and the arch one (x64)

@granteagon
Copy link

@granteagon granteagon commented Jul 11, 2016

@develar Why/How does your project not have an index.html file? Are you generating the HTML in JS and/or using iframe for the app content? Thanks

@develar
Copy link
Member

@develar develar commented Jul 12, 2016

@granteagon Web site (onshape.com) is loaded using BrowserWindow.

@develar
Copy link
Member

@develar develar commented Nov 10, 2016

  1. electron-builder doesn't use appdmg module anymore — no dev native deps from electron-builder anymore.
  2. electron-builder is smart now — dev native deps NEVER will be rebuild. Only production deps.

Enjoy. Version 8 will be released soon. You are not forced to use two package.json structure anymore.

@akashnimare
Copy link
Contributor

@akashnimare akashnimare commented Nov 12, 2016

You are not forced to use two package.json structure anymore.

@develar Thanks a ton man ❤️ .

@negamaxi
Copy link

@negamaxi negamaxi commented Nov 20, 2017

Similar problem here. Cannot find module 'module_name' in production build, but dev mode works well. All missed modules was not listed in package.json dependencies so I have to manually install them and it works.

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

Successfully merging a pull request may close this issue.

None yet
8 participants