Cannot use puppeteer because it fails loading yargs/yargs dependency

91 Views Asked by At

I'm trying to run a chromium browser on my AWS Lambda (node.js). This is the code I'm using

import chromium from 'chrome-aws-lambda';

...

  const browser = await chromium.puppeteer.launch({
    args: chromium.args,
    defaultViewport: chromium.defaultViewport,
    executablePath: await chromium.executablePath,
    headless: true,
    ignoreHTTPSErrors: true,
  });

  const page = await browser.newPage();

However, when running my application locally, this error is being thrown:

ERROR: Do not know how to load path: ../../node_modules/@puppeteer/browsers/node_modules/yargs/yargs

Inside the puppeteer library, it fails on this line:

const yargs_1 = __importDefault(require("yargs/yargs"));

Any idea on how to fix this?

Some relevant files:

tsconfig.json

  {
  "extends": "../../tsconfig.base.json",
  "compilerOptions":  { 
     
    "jsx": "react-jsx",
    /* Language and Environment */
    "target": "ES2015",
    "lib": [
      "es6",
      "DOM"
    ],

    /* Modules */
    "module": "commonjs" /* Specify what module code is generated. */,
    "resolveJsonModule": true /* Enable importing .json files */,

    /* Module Resolution */
    "baseUrl": "." /* This must be specified if "paths" is. */,

    /* JavaScript Support */
    "allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,
    "sourceMap": true /* Enables the generation of sourcemap files */,

    /* Emit */
    "declaration": true,
    "downlevelIteration": true,
    "outDir": "dist" /* Specify an output folder for all emitted files. */,

    /* Interop Constraints */
    "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
    "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

    /* Type Checking */
    "strict": true /* Enable all strict type-checking options. */,
    "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied `any` type.. */,
    "noEmitOnError": true,
    /* Completeness */
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  },
  "include": [
    "./config/**/*",
    "serverless.ts",
    "./src/**/*",
    "./lib/**/*",
    "./middleware/**/*",
    "./__tests__/**/*",
    "res/**/*",
    "**/*.tsx",
    "**/*"
  ]
}

0

There are 0 best solutions below