Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ousid's avatar
Level 3

The command "PATH=$PATH:/usr/local/bin NODE_PATH=`npm root -g` node

when i tried to generate a sitemap using laravel-sitemap by spatie team in localhost it gives me an empty sitemap.

    $path = public_path('/sitemap.xml');
    SitemapGenerator::create(env('APP_URL'))->writeToFile($path);

when upload the file into web server and tried to generate the sitemap it gives me this error:

The command "PATH=$PATH:/usr/local/bin NODE_PATH=`npm root -g` node '/path/to/project/vendor/spatie/browsershot/src/../bin/browser.js' '{"url":"https:\/\/coderflex.com\/","action":"content","options":{"args":[],"viewport":{"width":800,"height":600}}}'" failed. Exit Code: 1(General error) Working directory: /path/to/project/public Output: ================ Error Output: ================ internal/modules/cjs/loader.js:960 throw err; ^ Error: Cannot find module 'puppeteer' Require stack: - /path/to/project/vendor/spatie/browsershot/bin/browser.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15) at Function.Module._load (internal/modules/cjs/loader.js:840:27) at Module.require (internal/modules/cjs/loader.js:1019:19) at require (internal/modules/cjs/helpers.js:77:18) at Object.<anonymous> (/path/to/project/vendor/spatie/browsershot/bin/browser.js:1:19) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) at Module.load (internal/modules/cjs/loader.js:977:32) at Function.Module._load (internal/modules/cjs/loader.js:877:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) { code: 'MODULE_NOT_FOUND', requireStack: [ '/path/to/project/vendor/spatie/browsershot/bin/browser.js' ] }

any ideas?

0 likes
4 replies
Flor's avatar

Could be an issue with missing modules.

Error: Cannot find module 'puppeteer'

Have you run npm install on the server?

ousid's avatar
Level 3

Hey @flor Thanks for the reply.

i will give another shot by installing puppeteer

luciandex's avatar

I found a possible solution on internet. Run the following into your project root (or in workspace container if run in Docker).

$ which node

result ------> /usr/local/bin/node (may be different)

$ export NODE_PATH='/usr/local/bin/node' <---result

$ npm run dev <---- probably not neccessary to rerun this(?)

The problem is that node should not be installed as root. (as is stated by some developers)

Please or to participate in this conversation.