Hi,
After installing PuPHPeteer,
https://github.com/nesk/puphpeteer
i get this Fatal error when i test a basic function:
Fatal error: Uncaught Symfony\Component\Process\Exception\ProcessFailedException: The command “‘node’ ‘–inspect’ ‘/app/public/app/themes/musicdata/vendor/nesk/rialto/src/node-process/serve.js’ ‘/app/public/app/themes/musicdata/vendor/nesk/puphpeteer/src/PuppeteerConnectionDelegate.js’ ‘{“idle_timeout”:60,“log_node_console”:false,“log_browser_console”:false}’” failed. Exit Code: 127(Command not found) Working directory: /app/public Output: ================ Error Output: ================ sh: 1: exec: node: not found in /app/public/app/themes/musicdata/vendor/nesk/rialto/src/ProcessSupervisor.php on line 309
Here is my php script:
namespace App;
use Roots\Sage\Config;
use Roots\Sage\Container;
use Nesk\Puphpeteer\Puppeteer;
use Nesk\Rialto\Data\JsFunction;
use Nesk\Rialto\Exceptions\Node;
use Nesk\Puphpeteer\Resources\ElementHandle;
use Goutte\Client;
use Symfony\Component\DomCrawler\Crawler;
use DOMDocument;
use DOMXPath;
/**
* Scrapping with Google Puppeteer (php wrapper version)
* @link https://github.com/nesk/puphpeteer
* @link https://dev.to/alanmbarr/scraping-html-with-php-node-and-puppeteer-10m2
*/
function md_extract_with_puppeteer( $url ){
$url = 'https://alanmbarr.github.io/HackMidWestTimeline/';
if(empty($url)) return;
$puppeteer = new Puppeteer([
// Node's executable path
'executable_path' => 'node',
// How much time (in seconds) the process can stay inactive before being killed (set to null to disable)
'idle_timeout' => 60,
// How much time (in seconds) an instruction can take to return a value (set to null to disable)
'read_timeout' => 30,
// How much time (in seconds) the process can take to shutdown properly before being killed
'stop_timeout' => 3,
// A logger instance for debugging (must implement \Psr\Log\LoggerInterface)
'logger' => null,
// Logs the output of console methods (console.log, console.debug, console.table, etc...) to the PHP logger
'log_node_console' => false,
// Enables debugging mode:
// - adds the --inspect flag to Node's command
// - appends stack traces to Node exception messages
'debug' => true,
]);
/*
$browser = $puppeteer->launch([
'args' => ['--no-sandbox', '--disable-setuid-sandbox'],
]);
*/
$browser = $puppeteer->launch();
$page = $browser->newPage();
$page->goto($url);
$data = $page->evaluate(JsFunction::createWithBody('return document.documentElement.outerHTML'));
var_dump($page->content()); // Prints the HTML
$browser->close();
}
the error appears after this line:
$puppeteer = new Puppeteer
I test this on my local machine,i use Local By Flywheel (i’ve got the same error on my distant apache server).
My config is:
Web Server: Apache
PHP Version: 7.1.4
MySql: 5.5.60
Wordpress Version: 4.9.8
Node is installed globally, node version: 8.6.0
Here is my composer.json:
{
"name": "roots/sage",
"type": "wordpress-theme",
"license": "MIT",
"description": "WordPress starter theme with a modern development workflow",
"homepage": "https://roots.io/sage/",
"authors": [
{
"name": "Ben Word",
"email": "ben@benword.com",
"homepage": "https://github.com/retlehs"
},
{
"name": "Scott Walkinshaw",
"email": "scott.walkinshaw@gmail.com",
"homepage": "https://github.com/swalkinshaw"
},
{
"name": "QWp6t",
"email": "hi@qwp6t.me",
"homepage": "https://github.com/qwp6t"
}
],
"keywords": ["wordpress"],
"support": {
"issues": "https://github.com/roots/sage/issues",
"forum": "https://discourse.roots.io/"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
"require": {
"php": ">=7.1",
"composer/installers": "~1.0",
"illuminate/support": "~5.6",
"roots/sage-lib": "~9.0.1",
"soberwp/controller": "~9.0.0-beta.4",
"jwilsson/spotify-web-api-php": "^2.4",
"jolitagrazyte/discogs-api": "dev-master",
"fabpot/goutte": "^3.2",
"log1x/socialproof": "^0.1.2",
"nesk/puphpeteer": "^1.4"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.8.0",
"roots/sage-installer": "~1.3"
},
"scripts": {
"test": ["phpcs"],
"post-create-project-cmd": [
"Roots\\Sage\\Installer\\ComposerScript::postCreateProject"
]
}
}
The issue comes from Puppeteer. i have installed it in my sage theme using the following commands:
composer require nesk/puphpeteer
npm install @nesk/puphpeteer
I think the package can’t execute some node commands, because i get a Code 27 (sh: 1: exec: node: not found).
My purpose is to analyse some javascript rendered web pages.
Any help would be appreciate, i’m really stuck now