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

How to correctly call win-ca with app.asar? #1

Open
ghost opened this issue May 23, 2019 · 10 comments
Open

How to correctly call win-ca with app.asar? #1

ghost opened this issue May 23, 2019 · 10 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@ghost
Copy link

ghost commented May 23, 2019

I have added require('win-ca') at the top of the main.js file. It works fine when I am running the application from VS Code and when the modules are left unpacked. As part of the build process I am packaging electron using asar, i.e. with "build":{"asar": true}" in package.json. When I run it this way I am getting the following error.

Stack: Error: spawn path\to\electron\resources\app.asar\node_modules\win-ca\lib\roots ENOENT
at exports._errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:607:11)
at startup (bootstrap_node.js:167:16)
at bootstrap_node.js:589:3

I believe this is due to permission issues since the file exists. I've also tried
require('win-ca/fallback') with the same result.
I also noticed app.asar.unpacked directory is also created with win-ca inside. When I try to explicitly use this, i.e. require('path\to\electron\resources\app.asar.unpacked\node_modules\win-ca'), I get the following error.

Stack: Error: Cannot find module 'split'

My question is am I importing the package correctly given the way my app is set up? Have you run into this issue and know of a way to correctly implement?

@ukoloff
Copy link
Owner

ukoloff commented May 23, 2019

Unfortunately, I have no experience with asar, but what I understand:

I believe this is due to permission issues since the file exists

Nope, this is NOT permission issue. File win-ca\lib\root.exe cannot be run. This is Windows executable, it cannot run from archive (as far as I know), it should reside in regular folder.

Try patching fallback.js file before packing. Replace spawn[Sync] calls with execFile[Sync]. ASAR documentation states these API calls handle process spawning correctly. Should be investigated.

Stack: Error: Cannot find module 'split'

Folder app.asar.unpacked according to documentation contains only some files from ASAR archive, it obviously misses node_modules. If you plan to use unpacked archive - unpack it yourself with all contents. But then there is no point in using ASAR...

So far, it seems to me, current version of win-ca will NOT play good with ASAR. We should either patch it somehow or switch to another bundling method (or may be reject to pack win-ca at all).

@ukoloff ukoloff added the help wanted Extra attention is needed label May 23, 2019
@ukoloff ukoloff self-assigned this May 23, 2019
@ukoloff
Copy link
Owner

ukoloff commented May 24, 2019

I tested execFile. it works inside win-ca.

Now you should test it under asar.

This is fallback.js.zip to replace win-ca/lib/fallback.js. Pack to ASAR and test it working.

I think, you'd better mark win-ca/lib/roots.exe as unpack in ASAR, but it's up to you.

@ukoloff
Copy link
Owner

ukoloff commented Jun 26, 2019

win-ca v3.1.0 is out. Should work with ASAR.

@vogoltsov
Copy link

Still doesn't work in asar for me. Got the same problem:

Error: ENOENT, node_modules\win-ca\lib\roots not found in C:\Program Files\<program>\resources\app.asar
    at createError (electron/js2c/asar.js:126:17)
    at Object.func [as execFileSync] (electron/js2c/asar.js:161:27)
    at Object.run (C:\Program Files\<program>\resources\app.asar\node_modules\win-ca\lib\fallback.js:36:26)
    at Function.api (C:\Program Files\<program>\resources\app.asar\node_modules\win-ca\lib\index.js:56:10)
    at C:\Program Files\<program>\resources\app.asar\main\main.js:1:64478
    at new Promise (<anonymous>)
    at e.<anonymous> (C:\Program Files\<program>\resources\app.asar\main\main.js:1:64450)
    at step (C:\Program Files\<program>\resources\app.asar\node_modules\tslib\tslib.js:136:27)
    at Object.next (C:\Program Files\<program>\resources\app.asar\node_modules\tslib\tslib.js:117:57)
    at C:\Program Files\<program>\resources\app.asar\node_modules\tslib\tslib.js:110:75

Inspecting the asar shows the roots.exe file is there. I guess (couldn't confirm yet) one should use roots.exe instead of roots when executing from ASAR (see path.join(__dirname, 'roots') in fallback.js) - ASAR doesn't perform lookup of files inside with different extensions (unlike windows shell).

Another problem is you don't expose this as a configuration property for the application - see https://www.npmjs.com/package/regedit: it exposes path to executable VBS scripts through regedit.setExternalVBSLocation(...). It is a common practice to not pack these executables in asar and put them somewhere in the application directory.

@ukoloff
Copy link
Owner

ukoloff commented Oct 23, 2019

Still doesn't work in asar for me. Got the same problem:

Yeah, I cannot understand how this ASAR thing works at all.

Inspecting the asar shows the roots.exe file is there. I guess (couldn't confirm yet) one should use roots.exe instead of roots

This can do the trick, but I cannot test it right now. Can you patch fallback.js manually and add that .exe extension (line 6)?

Another problem is you don't expose this as a configuration property for the application - see https://www.npmjs.com/package/regedit: it exposes path to executable VBS scripts through regedit.setExternalVBSLocation(...).

I don't believe one should mess with this. It is hardly the case.

It is a common practice to not pack these executables in asar and put them somewhere in the application directory.

As I mentioned earlier, the problem is that I don't understand how ASAR works. I believe it should work seamlessly but it doesn't.

We can make some workarounds for ASAR of course (eg. to copy roots.exe to some temporary folder). But when to apply that scenario? If we are not under ASAR we shouldn't do all these stupid things.

I believe ASAR should do the job. It is responsible. For me everything should just work with ASAR as if no ASAR involved.

By the way, I tried to find source code of ASAR's execFile[Sync] and failed. Do you know where it is? One should rather make Pull Request to that repo, I suppose ;-)

@ukoloff
Copy link
Owner

ukoloff commented Oct 23, 2019

@vogoltsov I just published win-ca v3,1,1 with the only difference: roots.exe is used (instead of just roots).

Please try it with ASAR.

@Yiddishe-Kop
Copy link

I'm using v3.2.0, and get the same error:

Uncaught Error: ENOENT, node_modules\win-ca\lib\roots not found in C:\Users\yehudaneufeld\AppData\Local\Programs\jewishbooks-wiki\resources\app.asar
    at createError (electron/js2c/asar.js:111)
    at Object.func (electron/js2c/asar.js:146)
    at Object.module.<computed> [as execFile] (electron/js2c/asar.js:167)
    at Object.run (C:\Users\yehudaneufe…\lib\fallback.js:86)
    at api (C:\Users\yehudaneufe…-ca\lib\index.js:56)
    at Object.<anonymous> (C:\Users\yehudaneufe…-ca\lib\index.js:11)
    at Object.<anonymous> (C:\Users\yehudaneufe…ca\lib\index.js:128)
    at Module._compile (internal/modules/cjs/loader.js:967)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1004)
    at Module.load (internal/modules/cjs/loader.js:815)

@M0rious
Copy link

M0rious commented Jun 26, 2020

For me it works with
bin = path.join(__dirname, 'roots.exe');
in lib/fallback.js

@ukoloff
Copy link
Owner

ukoloff commented Jun 26, 2020

Well, v3.2.1 is published with @M0rious's patch.

Feel free to test and report.

@Yiddishe-Kop
Copy link

Works now for me!

Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants