i have problem when using spatie laravel-pdf on server. it working fine on localhost, but it showing error like the text below when i upload it to server
The command "PATH=$PATH:/usr/local/bin:/opt/homebrew/bin NODE_PATH=
npm root -g
node '/home/u1666881/public_html/royal_ambarrukmo/api/vendor/spatie/browsershot/src/../bin/browser.cjs' '{"url":"file:///tmp/1028804210-0397463001710232070/index.html","action":"pdf","options":{"args":[],"viewport":{"width":800,"height":600},"displayHeaderFooter":false,"margin":{"top":"2cm","right":"2cm","bottom":"2cm","left":"2cm"},"format":"a4","printBackground":true}}'" failed. Exit Code: 127(Command not found) Working directory: /home/u1666881/public_html/royal_ambarrukmo/api/public Output: ================ Error Output: ================ sh: npm: command not found sh: node: command not found
this is the code i use
return Pdf::view('leave', ['data' =>$leave, 'dp' => $dp, 'eo' => $eo, 'al' => $al, 'staff' => $staff, 'id'=> $id, 'ids' => $ids, 'users' => $users, 'quota' => $quota]) ->format('a4') ->margins(2, 2, 2, 2, Unit::Centimeter)->name('leave-'.now()->format('Y-m-d').'.pdf');
Spatie Laravel Pdf uses Browsershot and Puppeteer, Puppeteer is a node package. You will need Node +7.6 and Puppeteer installer on the server.
Assuming the server is Ubuntu. Install node.
sudo apt install nodejs
sudo apt install npm
Then install Puppeteer.
npm install puppeteer --location=global
This is also described in the documentation.