Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Spatie Browsershot cannot find node or npm when Laravel runs it

Your error

Symfony\Component\Process\Exception\ProcessFailedException2 more lines it can show

Fix it fast

Most common cause, 1 of 3

Node 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.

Fix
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'));
Did this fix it?
Full steps for this cause: check, fix, verify

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.

  • Applies to spatie/browsershot 5.5.0, Puppeteer 25.18, Node.js 22, 24 and 26 LTS, PHP-FPM
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
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-check

Then find the line you see in this list and open its fix:

  1. 1Node is installed under a user folder, such as nvm, that Browsershot does not searchwhich node prints a path like /home/forge/.nvm/versions/node/v24.x/bin/node, outside /usr/local/bin and /opt/homebrew/bin
  2. 2PHP-FPM clears the environment, so web requests run with a different PATHBrowsershot 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
  3. 3Node is not installed on the server, or it is too oldwhich node prints nothing over SSH, or node -v shows a version below 22

What does the error look like?

  • Symfony\Component\Process\Exception\ProcessFailedException
  • Exit 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.

Check
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.

Fix
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.

Verify
ls -l storage/app/example.pdf

Confirmed by spatie.be

Did this fix it?

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.

Check
grep -n "clear_env\|env\[PATH\]" /etc/php/*/fpm/pool.d/www.conf

Fix

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.

Fix
; /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.

Verify
curl -s https://your-app.example/path-check

Confirmed by php.net

Did this fix it?

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.

Check
node -v && npm -v

Fix

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.

Fix
node -v && npm -v
sudo npm install -g puppeteer
npx puppeteer browsers install chrome

Verify

node -v prints 22 or newer and a test render from tinker saves the PDF.

Verify
php artisan tinker --execute="Spatie\Browsershot\Browsershot::html('<h1>ok</h1>')->save(storage_path('app/ok.pdf'));"

Confirmed by spatie.be

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.