Reputation: 319
I'm trying to configure Spatie/Browsershot for a project, written in Laravel but after completing all of the steps, I still get one error:
'node' is not recognized as an internal or external command, operable program or batch file
A have installed the latest versions of node and npm and the both of them exist in the PATH and work on cmd as well.
Like it's written in the official documentation on GitHub, I've ran:
In the code I've written:
use Spatie\Browsershot\Browsershot;
//Method to generate some random id
$unique_id = uniqid('img_');
//The path to the node and npm folders
$path_node = realpath('C:\\"Program Files"\\nodejs');
$path_npm = realpath('C:\\Users\\Hristo\\AppData\\Roaming\\npm');
//The $content is actually a stored HTML code
Browsershot::html("$content")->setScreenshotType('jpeg', 100)
->setNodeBinary($path_node)
->setNpmBinary($path_npm)
->save("$unique_id.jpeg");
Program Files is with double quotation marks, otherwise Laravel throws me an error because of the white space in between the two words.
I'm not sure about the paths, are they correctly written? (the problem with the backslashes in windows)
Upvotes: 1
Views: 4297
Reputation: 325
This little snippet helped me with the problem. As long as OS environmental variables are pointing to the node.exe file you can put this into your code
->setNodeBinary('PATH %~dp0;%PATH%;') //~dp0 : fetches current directory path in windows
Hope you get it solved
Upvotes: 5
Reputation: 144
If you can run node -v
and get the version of your node. Then, the error was caused by the space between "Program Files". To solve this:
"C:\Programs\\nodejs\\node.exe"
. NOTE: THE .exe FILE IS REQUIRED HEREThis should be able to solve the issue.
Upvotes: 0