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

mstdmstd's avatar

How to run app with puppeteer on remote server

Hello,

In my laravel 5.8 app I managed to generate file with spatie/browsershot and download it ok, but to run it locally at my Ubuntu 18 I had ro run

    npm i puppeteer@next

as I got error :

    Error Output: ================ module.js:549 throw err; ^ Error: Cannot find module 'puppeteer' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load 

This decision I found at https://github.com/GoogleChrome/puppeteer/issues/2119 branch.

But after I installed the app at my server I got error :

    The command "PATH=$PATH:/usr/local/bin NODE_PATH=`npm root -g` node '/var/www/html/votes/vendor/spatie/browsershot/src/../bin/browser.js' '{"url":"file:\/\/\/tmp\/0046339001562826751\/index.html","action":"pdf","options":{"path":"generate_profile_card_ohTcbPxIiVNo5CUp8nIDJHbO8mKU2MhwCq4UFIbB_filename.pdf","args":[],"viewport":{"width":800,"height":600},"displayHeaderFooter":false,"printBackground":true}}'" failed. Exit Code: 1(General error) Working directory: /var/www/html/votes/public Output: ================ Error Output: ================ module.js:549 throw err; ^ Error: Cannot find module 'puppeteer' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object.<anonymous> (/var/www/html/votes/vendor/spatie/browsershot/bin/browser.js:1:81) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)

Installing laravel app on server I need to run

    composer install 

But not

    npm install

Yes ?

But I have to include /public/js/app.js file in /layouts/frontend.blade.php of my template. I suppose that puppeteer must be in this file?

my composer.json :


    {
        "name": "laravel/laravel",
        "description": "The Laravel Framework.",
        "keywords": ["framework", "laravel"],
        "license": "MIT",
        "type": "project",
        "require": {
            "php": "^7.1.3",
            "alaouy/youtube": "^2.2",
            "aloha/twilio": "^4.0",
            "arrilot/laravel-widgets": "^3.12",
            "cviebrock/eloquent-sluggable": "^4.5",
            "davejamesmiller/laravel-breadcrumbs": "5.x",
            "doctrine/dbal": "^2.8",
            "elasticquent/elasticquent": "dev-master",
            "facebook/graph-sdk": "^5.7",
            "fideloper/proxy": "^4.0",
            "google/apiclient": "^2.2",
            "intervention/image": "^2.4",
            "itsgoingd/clockwork": "^3.0",
            "jrean/laravel-user-verification": "^7.0",
            "laravel/framework": "5.8.*",
            "laravel/socialite": "^3.2",
            "laravel/tinker": "^1.0",
            "laravelium/sitemap": "^3.1",
            "maatwebsite/excel": "^3.1",
            "mews/captcha": "^2.2",
            "mews/purifier": "^2.1",
            "paypal/rest-api-sdk-php": "*",
            "proengsoft/laravel-jsvalidation": ">2.2.0",
            "s-ichikawa/laravel-sendgrid-driver": "~2.0",
            "snowfire/beautymail": "dev-master",
            "socialiteproviders/instagram": "^3.0",
            "spatie/browsershot": "^3.27",
            "spatie/laravel-activitylog": "^3.1",
            "spatie/laravel-backup": "^6.1",
            "spatie/laravel-feed": "^2.1",
            "spatie/laravel-image-optimizer": "^1.4",
            "spatie/laravel-newsletter": "^4.2",
            "spatie/laravel-sitemap": "^5.3",
            "spatie/laravel-tags": "^2.1",
            "spipu/html2pdf": "^5.2",
            "symfony/psr-http-message-bridge": "^1.2",
            "themsaid/laravel-mail-preview": "^2.0",
            "unisharp/laravel-filemanager": "^1.9",
            "wboyz/laravel-enum": "^0.2.1",
            "willvincent/feeds": "1.1.*",
            "yajra/laravel-datatables-oracle": "^9.0.0",
            "zendframework/zend-diactoros": "^2.1"
        },
        "require-dev": {
            "barryvdh/laravel-debugbar": "^3.1",
            "filp/whoops": "^2.0",
            "fzaninotto/faker": "^1.4",
            "mockery/mockery": "^1.0",
            "nunomaduro/collision": "^2.0",
            "orangehill/iseed": "^2.6",
            "phpunit/phpunit": "^7.0",
            "xethron/migrations-generator": "^2.0"
        },
        "autoload": {
            "classmap": [
                "database/seeds",
                "database/factories"
            ],
            "psr-4": {
                "App\": "app/"
            }
        },
        "autoload-dev": {
            "psr-4": {
                "Tests\": "tests/"
            }
        },
        "extra": {
            "laravel": {
                "dont-discover": [
                ]
            }
        },
        "scripts": {
            "post-root-package-install": [
                "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
            ],
            "post-create-project-cmd": [
                "@php artisan key:generate"
            ],
            "post-autoload-dump": [
                "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
                "@php artisan package:discover"
            ],
    
    
            "post-update-cmd": [
                "php artisan vendor:publish --provider=\"Proengsoft\JsValidation\JsValidationServiceProvider\" --tag=public --force"
            ]
    
        },
        "config": {
            "preferred-install": "dist",
            "sort-packages": true,
            "optimize-autoloader": true
        },
        "minimum-stability": "dev",
        "prefer-stable": true
    }

package.json:


    {
        "private": true,
        "scripts": {
            "dev": "npm run development",
            "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
            "watch": "npm run development -- --watch",
            "watch-poll": "npm run watch -- --watch-poll",
            "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
            "prod": "npm run production",
            "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
        },
        "devDependencies": {
            "axios": "^0.19.0",
            "bootstrap": "^4.3.1",
            "cross-env": "^5.1",
            "laravel-mix": "^4.0.16",
            "lodash": "^4.17.11",
            "popper.js": "^1.14.6",
            "vue": "^2.5.7"
        },
        "dependencies": {
            "bootstrap-colorpicker": "^3.1.2",
            "datatables.net-bs": "^1.10.19",
            "font-awesome": "^4.7.0",
            "jquery": "^3.4.1",
            "jquery-confirm": "^3.3.2",
            "laravel-echo": "^1.5.2",
            "mustache": "^2.3.0",
            "node-sass": "^4.12.0",
            "resolve-url-loader": "^2.3.1",
            "sass-loader": "^7.1.0",
            "vue-template-compiler": "^2.6.10"
        }
    }

How to fix this error on server(ubuntu 18 inder Digital Ocean) ?

Thanks!

0 likes
4 replies
mstdmstd's avatar

Searching for decision I found a way of installing puppeteer with command --save option :

npm i puppeteer --save

so I removed it at first :

npm remove puppeteer 

and

npm i puppeteer --save

after it. But It did not helped. Any idea how to fix it ?

mikenewbuild's avatar

It sounds like you may still need to "build" your js file for production.

Be sure to run the production command to compile your app's js file and then deploy it to the server.

npm run prod

Edit: just had a quick look at the browsershot package and checking that you have already followed the instructions to install Chrome on your server?

mstdmstd's avatar

You hit the point! As it is web server ubuntu it has never came to my head that I had to install Chrome as ordinary package? have I to run :

sudo apt-get install google-chrome-stable 

and it must fix my problems?

mikenewbuild's avatar
Level 22

I would recommend that you first follow the setup instructions on https://github.com/spatie/browsershot step by step to see if it resolves the issue. It includes instructions for all the packages required on a Ubuntu server.

1 like

Please or to participate in this conversation.