Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Packing with Electron #44

Open
rcrodrigues opened this issue May 17, 2017 · 4 comments
Open

Packing with Electron #44

rcrodrigues opened this issue May 17, 2017 · 4 comments

Comments

@rcrodrigues
Copy link

rcrodrigues commented May 17, 2017

Hi guys, I'm trying to pack this lib in an Electron app for windows.

It works perfectly fine for Linux, but when I build de app on a windows env, it gives an error saying
"Can't open ...\node_modules\phantom-html2pdf\lib\phantom-script.js".

When debugging the convert method, I saw that it's using the "__dirname" to build the path to that script.
Problem is when on a ASAR packed application, it won't be accessible.

Any ideas for a workaround?

@rcrodrigues
Copy link
Author

rcrodrigues commented May 17, 2017

Seems like the problem is that child_process.spawn() is requesting the file I mentioned above, and as
this method dosn't support ASAR files, then an error is thrown.
This was reported by @sindresorhus in this issue and this one

@rcrodrigues
Copy link
Author

Just letting you guys know. I managed to make this work in a packed Electron app! \o/

The trick is, because child_process.spawn() needs to run "phantom-html2pdf\lib\phantom-script.js",
we have to config the build on the package.json file to unpack phantom-html2pdf once the app is installed on the target.(Check this if you use electron-builder:options )

This way, we'll have no problems refferencing phantom-script in a ASAR pack.
Finally, all I had to do before packing my app, was change the line 83 of the file \lib\phantom-script.js
from path.join(__dirname, "phantom-script.js"), to path.join( __dirname.replace("app.asar", "app.asar.unpacked"), "phantom-script.js"),.

Let me know if a PR is welcome!

@dustin-H
Copy link
Member

Hi @rcrodrigues,

thanks for reporting this.

Sure, a PR is very welcome if it don't breaks support for other systems.

If you create one I will merge and publish as soon as I can. Please refer to this issue in your PR.

Thanks, and best wishes
Dustin

@rcrodrigues
Copy link
Author

@dustin-H

Although I believe changing that line wouldn't break support for any other system ( once ASAR is used on Electron apps only ), I couldn't run the test to make sure. Anyways, I'll make a PR changing that line of code and documenting it so other developers can know this can work in Electron.
I'll probably do it this weekend.

Thanks,
Renan

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants