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.
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.
来源:https://stackoverflow.com/questions/41085174/executing-a-script-inside-an-asar-archive