WebChimera.js
WebChimera.js copied to clipboard
Library not loaded: @rpath/libvlc.dylib
I'm getting this error when using the prebuilt binaries on macos BigSur:
App threw an error during load
Error: dlopen(/Users/ramtinsoltani/repos/misc/ash-player/webchimera.js/WebChimera.js.node, 1): Library not loaded: @rpath/libvlc.dylib
Referenced from: /Users/ramtinsoltani/repos/misc/ash-player/webchimera.js/WebChimera.js.node
Reason: image not found
at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1812)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1203:18)
at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1812)
at Module.load (internal/modules/cjs/loader.js:992:32)
at Module._load (internal/modules/cjs/loader.js:885:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12738)
at Module.require (internal/modules/cjs/loader.js:1032:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/ramtinsoltani/repos/misc/ash-player/webchimera.js/index.js:1:18)
at Module._compile (internal/modules/cjs/loader.js:1152:30)
I'm importing the package (index.js
) in Electron's main process.
Using electron 11.3.0
Any ideas?
Unfortunately I don't have any device supported by BigSur, so can't debug this issue myself. Sorry.
I found a few references that might help.
This might have something to do with asar packaging (though I'm only running my project with npx electron .
, so not really sure). I don't know anything about native modules, so I can't tests them myself.
https://github.com/electron-userland/electron-builder/issues/5238#issuecomment-712301089 https://github.com/electron-userland/electron-builder/issues/2738#issuecomment-378837434
I'll try to pack the application with asar: false
configuration and see if that helps.
Building with electron-builder
results in the following error:
⨯ ENOENT: no such file or directory, symlink '../../libvlccore.9.dylib' -> '/Users/ramtinsoltani/repos/misc/ash-player/dist/mac/Electron.app/Contents/Resources/app/webchimera.js/lib/vlc/lib/libvlccore.9.dylib'
- Native modules will not work from inside .asar
- Did you try prebuilt binaries? https://github.com/RSATom/WebChimera.js/releases/tag/v0.3.1
To get it working on MacOS you have to put libraries from VLC.app to right place in right format, and it can be tricky.
I'm using the prebuilt libraries and putting them in node_modules
. Also not using asar (as mentioned above).
Running npx electron .
doesn't work. Tried packing with asar: false
in the electron-builder
configuration but that results in the last error I shared here.
Would you please explain "you have to put libraries from VLC.app to right place in right format"? Is there anything I can try and report back to you?
If you already using prebuilt version - and it doesn't work, it's possible something was changed in libvlc or Electron, and it's possible I will have to look at it myself. The only issue, I could check it only on MacOS Catalina, so if your issuer related to BigSur some way, it will not help. Btw, are you on new Mac with M1 chip?
I would really appreciate that, my app development really depends on this since the whole thing is not possible without WebChimera.js.
I'm not on an M1 chip. I'm running it on a Macbook Air 2019.
Ok, I'll try to find time to look at it on this week.
Just to be sure, you was not able start your application with WebChimera.js embedded any single time, right? I mean your question not only about to pack Application for distributing, but about find way just run it, right?
Correct. No matter what mode the app is being run in (development using npx electron .
or packing) the moment WebChimera.js is being imported I get the @rpath
error. I've tried running it in the renderer process with webpack configuration (node-loader
), with require
in the main process, and with remote.require()
again in the renderer process. Packaging doesn't even go through.
The Windows prebuilt is running properly though.
@ramtinsoltani I think I've found the reason. The problem is Electron tries load libraries from @executable_path/../Frameworks
(i.e. from path related to Electron executable), and don't try load .dylib
s from near of WebChimera.js.node
. And now I need to think how to fix it right way.
As temporary workaround, you can try move all files from webchimera.js/lib
to electron/dist/Electron.app/Contents/Frameworks
, and then it should work fine.
That fixed the problem for now. Great catch!
Let me know if there's any help I can provide to fully fix this.
@RSATom I have the same issue, but during development (not after building the app).
It works fine on Windows, but not on Mac. So the issue seems to be related to this thread, but I am not sure how to apply the solution here during the development phase. I tried moving the files to the root of the package, but that didn't work either.
Node version: v14.17.3 Electron version: v11.1.0 WebChimera pre-built version: v0.3.1 Platform: macOS Big Sur v11.2.1
Any help here would be much appreciated. Thanks :)
@aziztitu I've temporarily fixed this issue by copying all the webchimera files to electron/dist/Electron.app/Contents/Frameworks
(the electron package in local node_modules
or the global node_modules
depending on where your electron installation is). You can also setup an npm script to automate this before packaging on MacOS. However, this is only a temporary fix and a real one should be eventually implemented either by @RSATom or a contributor with knowledge about native modules.
Let me know if this helped.
I just think it's bad idea copy any files to foreign dirs (i.e. not owned by WebChimera.js) automatically. On other side, I don't know how to force Electron load .dylibs from specific dir. So all we can do - create some "post install" script which developer can run by hand.
@ramtinsoltani That fixed it! Thank you so much!!
Although, I do get a lot of errors in the console like so:
I can live with that for now, and look into it more later if we don't have a solution right away.
And @RSATom, yes, I agree. Or at least, I think we should add this fix as an entry in the Known issues and workarounds section
@aziztitu good point
EDIT >>> I found a workaround for this issue by writing an afterpack file that moves the vlc dependencies automatically within the packed libraries.
@RSATom
I've managed to workaround this issue on local development env by pasting VLC and the *.dylib files into the electron frameworks folder as suggested, but couldn't do the same with the final build version.
It seems like the files should be in dist_electron/mac/XXX.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries
but they are missing in the build phase.
Pasting them manually into the app bundle under this path seem to work, but that breaks my deployment and signing phases.
Thanks
Do something like this:
# Set correct build target in `build_electron`.
./build_electron.sh
cd your/project/dir
mkdir -p vendor/webchimera
cp path/to/WebChimera.js/build/Release/WebChimera.node vendor/webchimera
cp -R /Applications/VLC.app/Contents/MacOS/lib vendor/webchimera/lib
@RSATom I don't know how to force Electron load .dylibs from specific dir.
The following script will modify the paths so they are relative to the .node
file.
#!/bin/sh
# Show initial paths.
otool -L WebChimera.js.node
otool -L lib/libvlc.dylib
# Allows us to resolve libvlc relative to .node file.
install_name_tool -change @rpath/libvlc.dylib @loader_path/lib/libvlc.dylib WebChimera.js.node
# Allows us to resolve libvlccore relative to libvlc.
install_name_tool -change @rpath/libvlccore.dylib @loader_path/libvlccore.dylib lib/libvlc.dylib
# Confirm changes.
otool -L WebChimera.js.node
otool -L lib/libvlc.dylib
NOTE: The script inside travis_before_deploy.sh
generates the full archive release which includes VLC.