ajmaleylia

Hi, I'm Ajmal
Ruby on Rails Developer

Troubleshooting Grover Gem: Puppeteer Module Not Found with ActiveJob and Deployment Tools

The Challenge

Are you encountering the dreaded Cannot find module puppeteer error when trying to run Grover? If you’re using ActiveJob with deployment tools like Tomo, Capistrano, or Mina, you’re not alone. Let’s dive into the problem and its solution.

The Setup

Our project uses:

The Problem

When attempting to run a screenshot service through GoodJob, you might encounter this error:

Error: Grover::DependencyError: Cannot find module 'puppeteer'. You need to add it to '/package.json' and run 'npm install'

This occurs because Grover can’t locate the Puppeteer module in the deployed environment.

The Solution

The key is to tell Grover where to find the root path of your application in the production environment. Here’s how:

  1. Create or open the file config/initializers/grover.rb
  2. Add the following configuration:
Grover.configure do |config|
  config.options = {}
  config.options[:root_path] = '/home/your_username/sites/your_app_name/current' if Rails.env.production?
end

Replace your_username and your_app_name with your actual deployment path details.

Why This Works

By setting the root_path option, you’re explicitly telling Grover where to look for the Puppeteer module in your production environment. This bypasses the issue of Grover not being able to automatically detect the correct path when running as a background job.

Reference

https://github.com/Studiosity/grover/issues/96#issuecomment-752787204