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

Crash when running as a packaged app with electron-builder on macOS #1

Closed
jwheare opened this issue Jul 20, 2016 · 12 comments
Closed

Comments

@jwheare
Copy link

jwheare commented Jul 20, 2016

Uncaught Exception:
TypeError: Expected string, got undefined
    at module.exports.name ([...]IRCCloud.app/Contents/Resources/app.asar/node_modules/env-paths/index.js:49:9)
    at ElectronConfig.Conf ([...]IRCCloud.app/Contents/Resources/app.asar/node_modules/conf/index.js:29:9)
    at ElectronConfig ([...]IRCCloud.app/Contents/Resources/app.asar/node_modules/electron-config/index.js:11:3)
    at setupConfig ([...]IRCCloud.app/Contents/Resources/app.asar/main.js:56:10)
    at Object.<anonymous> ([...]IRCCloud.app/Contents/Resources/app.asar/main.js:60:16)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)

env-paths expects a String, but conf is passing in an undefined opts.projectName, because electron-config is setting opts.cwd directly so it isn't needed.

This fails because the package.json isn't bundled into the asar file when built, so pkg-up finds nothing.

Not sure which package this should be fixed in.


Also, a fresh npm install results in this version tree:

└─┬ electron-config@0.2.1
  └─┬ conf@0.11.1
    └── env-paths@0.2.0

conf depends on env-paths: ^0.2.0 which won't allow 0.3.0

@sindresorhus
Copy link
Owner

sindresorhus commented Jul 20, 2016

Should be fixed in conf. It should not call envPaths() when cwd is set. I'll fix tomorrow. Weird that I didn't hit it. I'm using electron-config in multiple apps packaged with electron-packager and asar.

@jwheare
Copy link
Author

jwheare commented Jul 20, 2016

Actually, the package.json is getting included in the asar, but is still not being recognised.

I originally thought this was because we're using the dual package.json structure recommended by electron-builder, since our outer package.json has no name field set (it serves no purpose), but it's the inner package.json that gets bundled, so I'm a bit stumped.

Interesting to note that if there's a package.json outside the asar with a name field, the crash doesn't occur, but that's unlikely to happen if the .app gets copied to /Applications

@jwheare
Copy link
Author

jwheare commented Jul 20, 2016

Ah, this could be because both main.js and package.json are in the root of the asar, but it looks like conf is starting the hunt from the parent dir.

@jwheare
Copy link
Author

jwheare commented Jul 20, 2016

…hmm, unless that's the parent of the conf module, i.e. the node_modules dir.

@sindresorhus
Copy link
Owner

"Parent dir" being the directory of the parent (caller) module, which is your app.

@jwheare
Copy link
Author

jwheare commented Jul 20, 2016

The parent is actually the electron-config module. Docs say:

module.parent

<Object> Module object
The module that first required this one

conf isn't required directly from our app.

I added some logging, and here's the parent dir it starts on, and the package.json it finds:

~/src/irccloud/desktop/dist/mac/IRCCloud.app/Contents/Resources/app.asar/node_modules/electron-config
~/src/irccloud/desktop/package.json (outer, no name)

vs when running in dev mode, unpacked:

~/src/irccloud/desktop/app/node_modules/electron-config
~/src/irccloud/desktop/app/node_modules/electron-config/package.json (invalid, but unused anyway)

So it looks like it's having trouble traversing the asar tree. It should be finding the inner package.json at:

~/src/irccloud/desktop/dist/mac/IRCCloud.app/Contents/Resources/app.asar/package.json

Or unpacked at:

~/src/irccloud/desktop/app/package.json

@jwheare
Copy link
Author

jwheare commented Jul 20, 2016

Perhaps your path-exists isn't taking advantage of electron's patched fs calls that allow asar traversal:

https://github.com/electron/electron/blob/master/docs/tutorial/application-packaging.md#using-asar-archives

@sindresorhus
Copy link
Owner

There's nothing for path-exists to take advantage of. Asar patches all fs calls.

@jwheare
Copy link
Author

jwheare commented Jul 20, 2016

You're using fs.access(Sync) in path-exists, which isn't patched, but fs.exists(Sync) is:

https://github.com/electron/electron/blob/a0c5749ac1731afbbb7d042f1717597d6d68ea02/lib/common/asar.js#L342

@sindresorhus
Copy link
Owner

Ah, nice catch! That sounds like an Electron bug (You know what to do). Electron should be patching that fs.access{Sync,} too.

@jwheare
Copy link
Author

jwheare commented Jul 21, 2016

Cheers! There's still the issue of the incorrect module.parent, shall I open a separate ticket?

@sindresorhus
Copy link
Owner

@jwheare On conf, sure. Not a big issue though, as most would use conf directly, and electron-config doesn't make use of that feature anyways.

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

2 participants