4

Pretty simple. I am on Windows 8, I used the asar module to package a folder containing a node app.

I ran node app.asar and got the error

SyntaxError: Unexpected token ILLEGAL at exports.runInThisContext (vm.js:53:16) "(function (exports, require, module, __filename, __dirname) { ?"

where ? is clearly an invalid character.

Why does this archive contain invalid characters if I can run the app without issue before packaging it and asar archives are supposedly readable to a nodejs process

Daniel Olivier
  • 183
  • 2
  • 10

1 Answers1

7

You can't run asar packed file as normal Nodejs app, that's because asar is designed for Electron, not for ordinary Nodejs app. BUT! Try to install the electron as your project dependency or just ordinary modules

npm install electron

or install it globally

npm install -g electron

so you don't have to re install it on every project you have to run the packed asar file

and some notice: installing Electron is a bit longer because it's not normal modules

after you've done with the installation, try

electron file.asar

and test it if the app run as normal nodejs app

EDIT: maybe some time in near future you want try to package your "Nodejs App" with asar so the clien't wouldn't see your source code, and then deploy it to your client

here is the Electron way to publish your Electron App ( but perhaps, it can be used for another app as well ) GitHub Link

Community
  • 1
  • 1
deanrihpee
  • 178
  • 2
  • 11
  • Thanks for the answer. Unfortunately I need the node process to run as a service and electron refuses to do that. I have since found other solutions – Daniel Olivier Feb 13 '17 at 13:10
  • @DanielOlivier glad to hear you have the solution – deanrihpee Feb 13 '17 at 13:22
  • @DanielOlivier, Can you please tell me the solution? I have a similar use case I want to run my node app as system service. Thanks in advance. – Sai Teja Sep 20 '19 at 04:58