Spatie Browsershot cannot find node or npm when Laravel runs it
Fix it fast
Most common cause, 1 of 3Node is installed under a user folder, such as nvm, that Browsershot does not search
Pass the full paths to Browsershot, ideally from config so each server can set its own.
use Spatie\Browsershot\Browsershot;
Browsershot::url('https://example.com')
->setNodeBinary(config('services.browsershot.node', '/usr/local/bin/node'))
->setNpmBinary(config('services.browsershot.npm', '/usr/local/bin/npm'))
->save(storage_path('app/example.pdf'));Short answer
Browsershot runs node and npm as shell commands, so 'Exit Code: 127(Command not found)' means PHP could not find them. Node under a user folder such as nvm's, a PHP-FPM pool that clears PATH, or no Node on the server causes it. Pass full paths with setNodeBinary and setNpmBinary. Applies to Browsershot 5.5 with Node 22 or newer.
Which cause do you have?
On the server, as the deploy user, ask where node and npm live. Then compare with the PATH that web requests get. An nvm path in the first output points to cause 1, a short or empty PATH from the web route to cause 2, and no output from which to cause 3.
which node npm && node -v
# temporary route, delete it after the check:
# Route::get('/path-check', fn () => getenv('PATH'));
curl -s https://your-app.example/path-checkThen find the line you see in this list and open its fix:
- 1Node is installed under a user folder, such as nvm, that Browsershot does not search
which node prints a path like /home/forge/.nvm/versions/node/v24.x/bin/node, outside /usr/local/bin and /opt/homebrew/bin - 2PHP-FPM clears the environment, so web requests run with a different PATH
Browsershot works from php artisan tinker or a queue worker started in your shell, but fails inside a web request, and the path-check route shows a short PATH or nothing - 3Node is not installed on the server, or it is too old
which node prints nothing over SSH, or node -v shows a version below 22
What does the error look like?
Symfony\Component\Process\Exception\ProcessFailedExceptionExit Code: 127(Command not found)PATH=$PATH:/usr/local/bin:/opt/homebrew/bin NODE_PATH=`npm root -g`
Cause 1 of 3
Node is installed under a user folder, such as nvm, that Browsershot does not search
You seewhich node prints a path like /home/forge/.nvm/versions/node/v24.x/bin/node, outside /usr/local/bin and /opt/homebrew/bin
Check
Browsershot builds its command as PATH=$PATH:/usr/local/bin:/opt/homebrew/bin plus NODE_PATH from npm root -g, then runs node. Symfony Process labels exit code 127 as Command not found. nvm installs Node under ~/.nvm/versions/node/ and its own README warns that it is then available only to the user who installed it, so the web server's user and its PATH never see that folder.
ls -l "$(which node)" "$(which npm)"Fix
Pass the full paths to Browsershot, ideally from config so each server can set its own. The Spatie docs show both methods for exactly this case.
use Spatie\Browsershot\Browsershot;
Browsershot::url('https://example.com')
->setNodeBinary(config('services.browsershot.node', '/usr/local/bin/node'))
->setNpmBinary(config('services.browsershot.npm', '/usr/local/bin/npm'))
->save(storage_path('app/example.pdf'));Verify
The same request now writes the PDF, and the log shows no ProcessFailedException.
ls -l storage/app/example.pdfConfirmed by spatie.be
Cause 2 of 3
PHP-FPM clears the environment, so web requests run with a different PATH
You seeBrowsershot works from php artisan tinker or a queue worker started in your shell, but fails inside a web request, and the path-check route shows a short PATH or nothing
Check
PHP-FPM has a pool setting, clear_env, that defaults to yes. It wipes the environment of each worker before adding only the env entries written in the pool file. So the PATH you see over SSH never reaches Browsershot when it runs inside an HTTP request.
grep -n "clear_env\|env\[PATH\]" /etc/php/*/fpm/pool.d/www.confFix
Add a PATH entry to the pool configuration that includes the folder holding node, then restart PHP-FPM. If you cannot edit the pool, set the search path per call with setIncludePath instead.
; /etc/php/<version>/fpm/pool.d/www.conf
env[PATH] = /usr/local/bin:/usr/bin:/bin
// or in PHP, per call
Browsershot::html('Foo')->setIncludePath('$PATH:/usr/local/bin:/usr/bin');Verify
After the restart, the path-check route prints the new PATH and the web request produces the file.
curl -s https://your-app.example/path-checkConfirmed by php.net
Cause 3 of 3
Node is not installed on the server, or it is too old
You seewhich node prints nothing over SSH, or node -v shows a version below 22
Check
The package needs Node 22 or higher and Puppeteer 23 or higher. A project that worked on a laptop often lands on a server where only PHP was set up, so the first shell lookup for node fails with the same exit code.
node -v && npm -vFix
Install a current Node LTS with your usual method, then install Puppeteer and a Chrome build for it, as the Spatie requirements page shows for Ubuntu servers.
node -v && npm -v
sudo npm install -g puppeteer
npx puppeteer browsers install chromeVerify
node -v prints 22 or newer and a test render from tinker saves the PDF.
php artisan tinker --execute="Spatie\Browsershot\Browsershot::html('<h1>ok</h1>')->save(storage_path('app/ok.pdf'));"Confirmed by spatie.be
How do I stop it coming back?
- Keep the node and npm paths in config or .env per server, and call setNodeBinary and setNpmBinary everywhere Browsershot is used.
- Install Node in a system folder such as /usr/local/bin on servers that run PHP-FPM, instead of under a user's nvm.
- Add a health check that renders a one-line PDF after each deploy, so a missing binary shows up before users hit it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Spotless Laundry, EZ Estimater, TaxiDex.