I am writing a small app that utilises serialport as dependency (which itself has native dependencies).
When starting the app in dev mode (npm-run-all --parallel bundle serve) everything is working fine. I am using electron-rebuild as postinstall script to compile the native dependencies for the used Electron (4.0.0) version.
When building the app for production issuing yarn build && electron-builder build --publish never, I cannot start the app bundle with the following error in the macOS log:
Dyld Error Message:
Symbol not found: __ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorE
Referenced from: /var/folders/*/.com.my.app.a9yuVC
Expected in: flat namespace
After I have tried building the app, I am no longer able to start the app in dev mode with the shown command.
This error is shown when starting the app in dev mode:
dyld: lazy symbol binding failed: Symbol not found: __ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorE
Referenced from: /Client/node_modules/@serialport/bindings/build/Release/bindings.node
Expected in: flat namespace
dyld: Symbol not found: __ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorE
Referenced from: /Client/node_modules/@serialport/bindings/build/Release/bindings.node
Expected in: flat namespace
I have to run $(npm bin)/electron-builder install-app-deps first, only after that I can start the app in dev mode again.
Running ($npm bin)/electron-rebuild does not work for some reason.
It seems, that this is an issue with the packaging.
I am quite new to all the electron, nodejs stuff so I do not think this is a bug. Probably my configuration is wrong.
Could anyone please help me out?
EDIT:
I've created a small test application to reproduce the issue.
Maybe it's helpful. https://github.com/phhoef/serialport-test
I'm seeing the same issue.
I have the "postinstall": "electron-builder install-app-deps", added to my package.json
After running yarn I see
$ electron-builder install-app-deps
• electron-builder version=20.38.4
• loaded configuration file=package.json ("build" field)
• rebuilding native production dependencies platform=darwin arch=x64
• rebuilding native dependency name=fsevents
• rebuilding native dependency name=keytar
✨ Done in 8.07s.
Then when I start I get this message:
$ webpack-dev-server --hot --host 0.0.0.0 --config=./webpack.dev.config.js --mode development
ℹ 「wds」: Project is running at http://0.0.0.0:8080/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from ..redacted../dist
ℹ 「wds」: 404s will fallback to /index.html
dyld: lazy symbol binding failed: Symbol not found: __ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorE
Referenced from: ..redacted../node_modules/keytar/build/Release/keytar.node
Expected in: flat namespace
dyld: Symbol not found: __ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorE
Referenced from: ..redacted../node_modules/keytar/build/Release/keytar.node
Expected in: flat namespace
✨ Done in 1.57s.
When I run $(npm bin)/electron-builder install-app-deps I see:
• electron-builder version=20.38.4
• loaded configuration file=package.json ("build" field)
• rebuilding native production dependencies platform=darwin arch=x64
And after that the app starts normally.
When I try to release the app, it runs the install-app-deps again as it did with the postinstall
And this causes the same crash in the release version.
"electron": "^4.0.1",
"electron-builder": "^20.38.4",
I noticed something else as well
After yarn install this is the contents of the keytar build folder

After $(npm bin)/electron-builder install-app-deps
This is the result of the build folder

Same issue here using the keytar (4.3.0) dependency.
This may be due to an issue where the ABI for both Electron v3 and v4 is 64, but the builds are not compatible: lgeiger/node-abi#55
@gniezen, thanks for your help.
Honestly, I do not completely understand the cause as I am quite new to Electron/Node.js.
I looked over your linked ticket, but didn't see a solution.
I executed $(npm bin)/electron --abi in the project root. The result is 64.
iMac:Client ph$ $(npm bin)/electron --abi
64
As far as I know, serialport does not have prebuilt binaries for Electron 4 (but for 3).
The issue is, that due to mixing up the version numbers, Electron is using the wrong prebuilt binaries, right?
Is there anything I can do about?
I also do not understand, why it is working when running electron-builder install-app-deps. This command re-compiles the native binaries for the right Electron version?
But why is it not possible to add this command to my package script?
@phhoef Have you tried downgrading your serialport to 6.2.2? v7 doesn't seem to work on macOS and Linux in any case: https://github.com/node-serialport/node-serialport/issues/1770
Yes, it's also my understanding that due to them using the same ABI, Electron v4 tries to use the prebuilt binaries made for Electron v3. The only solutions I see at this stage:
serialport to v6electron-builder config)I just saw, that there is a new version of [email protected].
I changed the package.json and run yarn install.
Now, the problem seems to be fixed. I don't know if it's really the new version or anything related to the prebuilt binaries.
Anyhow, when executing the script yarn package I am able to open the App.
@phhoef I still have the problem we keytar...
@benoist I downgraded keytar to v4.2.1 as a workaround.
Most helpful comment
I'm seeing the same issue.
I have the "postinstall": "electron-builder install-app-deps", added to my package.json
After running yarn I see
Then when I start I get this message:
When I run $(npm bin)/electron-builder install-app-deps I see:
And after that the app starts normally.
When I try to release the app, it runs the install-app-deps again as it did with the postinstall
And this causes the same crash in the release version.