Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
Issue running puppeteer in github actions

Everything works fine locally, but when I try to run my script using puppeteer in github action, I get this:

file:///dist/index.js:49412
    const puppeteerRootDirectory = pkg_dir_1.default.sync(__dirname);
                                                          ^

ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/dist/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

I've tried defining the __dirname before importing puppeteer but haven't had any luck. e.g.

import {dirname} from "path";
globalThis.__dirname = dirname(import.meta.url);
import puppeteer from "puppeteer";

EDIT:

This appears to be an issue with compiling via ncc. I can repro locally when I run ncc run [my script]. I've looked into how to define __dirname for modules but am still running into issues. I tried something like this and adding it at the top of my script before my import statement but it doesn't make a difference. Is there anywhere I can add it that it would be recognized by puppeteer?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!