I am experiencing strange behavior of a process (Illuminate\Support\Facades\Process) running through Laravel 10 scheduler on a VPS and I really don't know how is this happening or how to fix this behavior.
Crontab takes care of starting the Laravel scheduler, the cron job looks like this:
* * * * * root cd /var/www/stage.betvia.sk/public_html/ && /usr/bin/php artisan schedule:run >> /var/www/stage.betvia.sk/logs/checkscheduler.txt 2 >&1
There is a command in the scheduler that executes a process - it's a node js command (I'm using node version 18.16.1)
$process = Process::forever()->run(implode(" ", $process_data['process']));
if (!$process->successful()) {
$this->log($LOG_CHANNEL, 'error', 'Partial process was not successful - failed parsing.');
$this->log($LOG_CHANNEL, 'info', json_encode($process->errorOutput()));
continue;
}
If I type the command directly to the console on the VPS, it works as it should.
But if scheduler runs this command, the process fails right at the beginning with this error:
"\/var\/www\/stage.betvia.sk\/public_html\/node_modules\/jsdom\/lib\/api.js:140
referrer: req.getHeader(\"referer\") ?? undefined
SyntaxError: Unexpected token ?
at Module._compile (internal\/modules\/cjs\/loader.js:723:23)
at Object.Module._extensions..js (internal\/modules\/cjs\/loader.js:789:10)
at Module.load (internal\/modules\/cjs\/loader.js:653:32)
at tryModuleLoad (internal\/modules\/cjs\/loader.js:593:12)
at Function.Module._load (internal\/modules\/cjs\/loader.js:585:3)
at Module.require (internal\/modules\/cjs\/loader.js:692:17)
at require (internal\/modules\/cjs\/helpers.js:25:18)
at Object.<anonymous> (\/var\/www\/stage.betvia.sk\/public_html\/storage\/parsers\/parser_1\/parser_source.js:1:13)
at Module._compile (internal\/modules\/cjs\/loader.js:778:30)
at Object.Module._extensions..js (internal\/modules\/cjs\/loader.js:789:10)"
I'm not sure if this is important (probably is), but here is the beginning of the node JS file:
var jsdom = require("jsdom");
var JSDOM = jsdom.JSDOM;
var window = new JSDOM().window;
var document = window.document;
var navigator = require("navigator");
var jQuery = require("jquery")(window);
var glob_fcn;
It looks like it has a problem with the first line but not sure why, jsdom is installed
"jsdom": "^22.1.0",
I have already tried to remove the node_modules, reinstall node and google the issue but no success.
Can anyone explain why is the command working fine if I type it manually to the console but doesn't work when the scheduler executes it? Scheduler also executes some Python 3 commands but they work fine, I have problems just with the node JS ones.