Skip to content

Error launching simple script: Error [ERR_REQUIRE_ESM]: require() of ES Module #73

Closed
@Komakino-joy

Description

@Komakino-joy

I am trying to run the code below, but keep getting this error, has anyone else ran into this issue ?

ERROR

C:localRepo\node_modules\ts-node\dist\index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:localRepo\node_modules\camoufox-js\dist\index.js from C:localRepo\src\simpleCamoufoxScript.ts not supported.
Instead change the require of index.js in C:localRepo\src\simpleCamoufoxScript.ts to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (C:localRepo\node_modules\ts-node\dist\index.js:851:20)
    at Object.<anonymous> (C:localRepo\src\simpleCamoufoxScript.ts:3:23)
    at m._compile (C:localRepo\node_modules\ts-node\dist\index.js:857:29)
    at require.extensions.<computed> [as .ts] (C:localRepo\node_modules\ts-node\dist\index.js:859:16)
    at phase4 (C:localRepo\node_modules\ts-node\dist\bin.js:466:20)
    at bootstrap (C:localRepo\node_modules\ts-node\dist\bin.js:54:12)
    at main (C:localRepo\node_modules\ts-node\dist\bin.js:33:12)
    at Object.<anonymous> (C:localRepo\node_modules\ts-node\dist\bin.js:579:5) {
  code: 'ERR_REQUIRE_ESM'
}

SCRIPT

import { launchOptions } from "camoufox-js";
import { firefox } from "playwright";
import { proxyConfig } from "./config";
import { sleep, debug } from "./utils";

const { proxyIp, proxyUser, proxyPass, proxyUrl, proxyPort } = proxyConfig;
if (!proxyUrl || !proxyIp || !proxyUser || !proxyPass) throw Error("Proxy Address is required.");

const main = async () => {
  try {
    debug("[Checkpoint] Connecting to Camoufox browser...");
    const browser = await firefox.launch({
      ...(await launchOptions({
        headless: false,
        humanize: true,
        debug: false,
        block_images: false,
        geoip: true,
        enable_cache: false,
        proxy: {
          server: `http://${proxyIp}:${proxyPort}`,
          username: proxyUser as string,
          password: proxyPass as string,
        },
      })),
      // other Playwright options, overriding the Camoufox options
    });

    await browser.newPage();

    await sleep(1000 * 1 * 60 * 20);
  } catch (error) {
    debug(`Error: ${(error as any).message}`);
    throw error;
  } finally {
    debug("Stopping server and browser...");
    debug("Cleanup completed");
  }
};

main().catch(console.error);

Metadata

Metadata

Assignees

Labels

t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions