javascriptnode.jsasar

Node JS unable to execute asar archive


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


Solution

  • 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