Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a script inside an ASAR archive

Tags:

node.js

asar

I am attempting to run a script that is archived inside an ASAR file like so:

var spawn  = require('child_process').spawn;

var t = spawn('node', ['./bundle.asar/main.js'], {});

t.on('data', function(data){      
  console.log(data.toString());
});

t.stdout.pipe(process.stdout);
t.stderr.pipe(process.stderr);

FYI the above script is situated outside the ASAR archive. However, all I get is the following error:

Cannot find module 'C:\Users\MyUser\tests\asar-test\bundle.asar\main.js'

The official docs on this particular issue are nonexistent. Is there some way to either read the ASAR file or require a script inside it? Thank you.

like image 739
Unforgiven Avatar asked Jul 17 '26 14:07

Unforgiven


1 Answers

For posterity, the answer to this is to require your .js file like so:

var spawn  = require('child_process').spawn;
var myScript = require('./bundle.asar/main.js');

var t = spawn('node', [myScript], {});

t.on('data', function(data){      
  console.log(data.toString());
});

t.stdout.pipe(process.stdout);
t.stderr.pipe(process.stderr);

Hope this helps.

like image 170
Unforgiven Avatar answered Jul 19 '26 03:07

Unforgiven



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!