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

OSX .dylib loading issue with Electron/asar #123

Closed
garlitzj opened this issue Feb 14, 2017 · 20 comments
Closed

OSX .dylib loading issue with Electron/asar #123

garlitzj opened this issue Feb 14, 2017 · 20 comments

Comments

@garlitzj
Copy link

On OSX, when I package my Electron app as an asar, Greenworks can't find the dylib files. However, without asar it works just fine. Moving the .dylib files to a default directory such as /usr/local/lib seems to solve the problem, but I was hoping to find a more elegant solution or some direction as to where the .dylib files would need to go in this context. I've tried including dylib files as extraResources, as extraFiles, and even moving them into the same folder as the .app to no avail. Any ideas? Thanks!

@hokein
Copy link
Member

hokein commented Feb 14, 2017

@garlitzj Could you list your app directory?

@garlitzj
Copy link
Author

garlitzj commented Feb 14, 2017

Hi, here is the general structure of the app directory as it pertains to Greenworks. It's virtually identical to the example in the readme:

|-- lib
| |-- greenworks-linux32.node
| |-- greenworks-linux64.node
| |-- greenworks-osx64.node
| |-- greenworks-win32.node
| |-- libsdkencryptedappticket.dylib
| |-- libsteam_api.dylib
|-- greenworks.js
< other directories >
<other .js files>
|-- index.html
|-- package.json

Again, if I don't package the app as an asar, it loads properly. But once I package as an asar, it can no longer find the library files, and Greenworks fails to start. That's the strange part. There haven't been any such issues with Windows or Linux, so I'm not sure if it's something I'm missing.

@hokein
Copy link
Member

hokein commented Feb 14, 2017

What's the specific error message? Have you read #102? it maybe helpful to resolve your issue.

@MadSpyxFR
Copy link
Contributor

@garlitzj
Copy link
Author

Hi, thanks for the responses. I'll research those links and try those later as soon as I can.

The error I'm getting is the Library not loaded: @loader_path/libsteam_api.dylib issue, which I assume means Greenworks itself is being loaded. I know that's on the troubleshooting page, but the error only ever happens with asar turned on. With asar off, it loads without issue. As far as I can tell, the dylib files are in the correct place prior to the app being packaged, but something about the packaging is throwing off where it's trying to load them from?

@hokein
Copy link
Member

hokein commented Mar 3, 2017

@garlitzj Sorry for the lonnnng delay. Sounds like a Greenworks issue. Could you provide a minimal sample which can reproduce the issue? It would help us a lot to track down the issue.

@Cleod9
Copy link

Cleod9 commented Apr 4, 2017

@garlitzj Have you tried unpacking the entire lib folder via asar's unpack option?

https://github.com/electron/electron/blob/master/docs/tutorial/application-packaging.md#adding-unpacked-files-in-asar-archive

I had to do this to get asar to work at all on Windows. I suspect other OSes may have a similar issue, especially if it's related to files alongside the *.node files

(in my case I'm using electron-packager and used its unpackDir option to extract the whole lib folder)

@hokein
Copy link
Member

hokein commented May 25, 2017

Thanks for @Cleod9's reply.
I'm closing this as it has been silent for a while. Feel free to reopen it if you have any problem.

@hokein hokein closed this as completed May 25, 2017
@Zamiell
Copy link
Contributor

Zamiell commented Dec 4, 2017

I'm also getting this issue when building my app for macOS for the first time.

Mon Dec 04 03:14:56 EST <info> main.js:105 - +---------------------------------+
Mon Dec 04 03:14:56 EST <info> main.js:106 - | Racing+ client v0.14.9 started! |
Mon Dec 04 03:14:56 EST <info> main.js:107 - +---------------------------------+
Mon Dec 04 03:14:57 EST <info> main.js:119 - { message: 'Error: dlopen(/var/folders/sv/n24rv4254cz5kwg9zj55t12r0000gn/T/.org.electron.IsaacRacingPlus.uGG09w, 1): Library not loaded: @loader_path/libsteam_api.dylib\n  Referenced from: /var/folders/sv/n24rv4254cz5kwg9zj55t12r0000gn/T/.org.electron.IsaacRacingPlus.uGG09w\n  Reason: image not found',
  exception: 
   [ { type: 'Error',
       value: 'dlopen(/var/folders/sv/n24rv4254cz5kwg9zj55t12r0000gn/T/.org.electron.IsaacRacingPlus.uGG09w, 1): Library not loaded: @loader_path/libsteam_api.dylib\n  Referenced from: /var/folders/sv/n24rv4254cz5kwg9zj55t12r0000gn/T/.org.electron.IsaacRacingPlus.uGG09w\n  Reason: image not found',
       stacktrace: [Object] } ],
  culprit: 'main at Object.<anonymous>',
  user: {},
  tags: {},
  extra: {},
  breadcrumbs: { values: [] },
  request: {},
  modules: 
   { 'fs-extra': '4.0.2',
     universalify: '0.1.1',
     'graceful-fs': '4.1.11',
     jsonfile: '4.0.0',
     'electron-updater': '2.16.3',
     'source-map-support': '0.5.0',
     'source-map': '0.6.1',
     'lazy-val': '1.0.2',
     'builder-util-runtime': '3.3.0',
     debug: '3.1.0',
     ms: '2.0.0',
     'bluebird-lst': '1.0.5',
     bluebird: '3.5.1',
     semver: '5.4.1',
     'electron-is-dev': '0.3.0',
     raven: '2.2.1',
     cookie: '0.3.1',
     'timed-out': '4.0.1',
     lsmod: '1.0.0',
     'stack-trace': '0.0.9',
     uuid: '3.0.0',
     opn: '5.1.0',
     'is-wsl': '1.1.0',
     tracer: '0.8.11',
     tinytim: '0.1.1',
     dateformat: '2.0.0',
     colors: '1.1.2',
     'teeny-conf': '1.1.0' },
  server_name: 'Jamess-MacBook-Air.local',
  environment: 'production',
  logger: '',
  event_id: 'ba74f0d92de049549ed5b5125d3b1812',
  timestamp: '2017-12-04T08:14:57',
  project: '124813',
  platform: 'node',
  release: 'v0.14.9' }

It only happens after the app is already packaged up for production. In other words, when everything is in an Asar archive.

Can we reopen the issue? For reference, my repository is isaac-racing-client.

Steps to reproduce:

  • git clone https://github.com/Zamiell/isaac-racing-client.git
  • cd isaac-racing-client
  • npm install --ignore-scripts git+https://github.com/greenheartgames/greenworks.git
  • Put steamworks_sdk in the deps folder.
  • npm install
  • npm run pack
  • Double click on dist/mac/Racing+.app.
  • Read the log file at ~/Library/Logs/Racing+\ 2017-12-04.log.

@Zamiell
Copy link
Contributor

Zamiell commented Dec 4, 2017

@Cleod9
Copy link

Cleod9 commented Dec 4, 2017

@Zamiell The error info you wrote "Reason: image not found'" doesn't look like it's from Greenworks. But assuming that line number in main.js is truly where it's erroring, have you tried copying greenworks.js into your repo directly rather than using NPM? I've found that including greenworks as an NPM package is essentially useless, and it was far easier to just save the greenworks.js file locally and use the pre-built binaries on the Releases page.

@Zamiell
Copy link
Contributor

Zamiell commented Dec 5, 2017

@Cleod9 Back when I started my Greenworks project, I couldn't even get the compiled releases to work at all, which is why I bothered to compile them myself in the first place. But yeah, I just tried out the compiled releases again. However, now I get this error (running from npm start in development):

C:\Repositories\isaac-racing-client>npm start

> RacingPlus@0.14.13 start C:\Repositories\isaac-racing-client
> electron .


App threw an error during load
Error: The specified module could not be found.
\\?\C:\Repositories\isaac-racing-client\src\lib\greenworks-win64.node
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)

    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Repositories\isaac-racing-client\src\greenworks.js
:17:18)
    at Object.<anonymous> (C:\Repositories\isaac-racing-client\src\greenworks.js
:133:3)

No idea what is going on, but C:\Repositories\isaac-racing-client\src\lib\greenworks-win64.node clearly exists, as I'm staring right at it, and I don't see any typos or anything.

Any tips?

@Cleod9
Copy link

Cleod9 commented Dec 5, 2017

@Zamiell So your app's root is the isaac-racing-client directory? I recommend having your app built into its own dedicated app/ directory. Greenworks is going to look in [app_root]/lib for those binaries, so if you place them under src/lib then it's not going to work. You can probably confirm by running electron . while in the src directory instead and make adjustment to your entry point. (Aside fyi: I had trouble with things like electron ./src so you're better off running path/to/electron . regardless of how you set it up)

@Zamiell
Copy link
Contributor

Zamiell commented Dec 5, 2017

@Cleod9

  1. The app's root is the isaac-racing-client directory, yes. That's where the package.json file is, which shows that npm start is equivalent to electron ..

  2. I:

  • moved the lib folder down one directory
  • moved the greenworks.js file down one directory
  • changed
    • const greenworks = include('./greenworks') to
    • const greenworks = include('../greenworks')

I still get the exact same error, so are you sure the issue is with it being in a subdirectory?

@Cleod9
Copy link

Cleod9 commented Dec 5, 2017

@Zamiell Hmm, strange since i had a similar issue before I finally moved lib to the correct directory. Can you paste the new stack trace?

@Zamiell
Copy link
Contributor

Zamiell commented Dec 5, 2017

It's the exact same stack trace:

C:\Repositories\isaac-racing-client>npm start

> RacingPlus@0.14.13 start C:\Repositories\isaac-racing-client
> electron .


App threw an error during load
Error: The specified module could not be found.

\\?\C:\Repositories\isaac-racing-client\lib\greenworks-win64.node
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Repositories\isaac-racing-client\greenworks.js:17:18)
    at Object.<anonymous> (C:\Repositories\isaac-racing-client\greenworks.js:133:3)
Terminate batch job (Y/N)? 

@Cleod9
Copy link

Cleod9 commented Dec 5, 2017

@Zamiell Ok thanks, I just wanted to confirm. I suspect that with your setup you should still place greenworks.js in your src/ folder, but keep the lib/ folder at the root. Your package.json is basically telling Electron to use .src/main.js as the entry point, but the current working directory for the app is still at isaac-racing-client.

If that still doesn't work, try reverting to your original setup but running this instead and see what happens:

cd src
..\node_modules\.bin\electron .

@Zamiell
Copy link
Contributor

Zamiell commented Dec 5, 2017

I kept the lib folder at the root as you recommended and I get a slightly different error message, which is much more generic, which leads me to believe that your hypothesis about Electron looking for stuff in the root of the repository is false:


> RacingPlus@0.14.13 start C:\Repositories\isaac-racing-client
> electron .


App threw an error during load
Error: Cannot find module './lib/greenworks-win64'
    at Module._resolveFilename (module.js:485:15)
    at Function.Module._resolveFilename (C:\Repositories\isaac-racing-client\node_modules\electron\dist\resources\electron.asar\common\reset-search-paths.js:35:12)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Repositories\isaac-racing-client\src\greenworks.js:17:18)
    at Object.<anonymous> (C:\Repositories\isaac-racing-client\src\greenworks.js:133:3)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)

I reverted to my original setup and did those commands, leading in an Windows error window popping up:

Error launching app

Unable to find Electron app at C:\Repositories\isaac-racing-client\src

Cannot find module 'C:\Repositories\isaac-racing-client\src'

Any other ideas? Feel free to look at the layout of my repository, which doesn't seem very unusual, at least to me.

@Cleod9
Copy link

Cleod9 commented Dec 6, 2017

  1. You might be right, though I'm still very suspicious of how electron is seeing your file system. Have you tried console logging some path info in your app to see if the binaries are visible from there?

  2. Your app setup looks pretty similar to most electron repos I've seen, if anything mine is the odd one out and it works fine. Just to give you an idea on how my app is set up, I actually have a separate directory for my application's source files and the app itself:

app/
----lib/
----main.js (bundled app code)
----greenworks.js
----package.json
source/
----morecode/*.js
----main.js
----package.json

But the principle is the same, I'm just bundling code with webpack first and spitting it out in the app directory to keep the source separated from the built app. For quick tests i usually run the app with the command i posted before while in the app/ directory: ..\node_modules\.bin\electron ..

@Eyesiah
Copy link

Eyesiah commented Apr 6, 2018

Hi,
I'm also getting this problem (the one in the original post: the greenworks init fails with "Reason: image not found" when running the game with an asar, but when unpacking the asar, the init succeeds.

This is the structure:

Electron.app
app.asar
-play-electron.html
-greenworks.js
-steam_appid.txt
-lib/
--greenworks-osx64.node
--libsteam_api.dylib
--libsdkencryptedappticket.dylib

Any help would be appreciated.

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

6 participants