Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda