3

I deployed an API route handler with Next.js 13 that uses Puppeteer. When I call this api route in production, I get this error message in 'Function Logs':

[POST] /api/getLinkedin
00:00:21:62
2023-02-02T00:00:23.103Z    7545c99c-ea8f-41d3-8771-97eb786502cb    ERROR   Error: Could not find Chromium (rev. 1083080). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npm install`) or
 2. your cache path is incorrectly configured (which is: /home/sbx_user1051/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
    at ChromeLauncher.resolveExecutablePath (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:127:27)
    at ChromeLauncher.executablePath (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:205:25)
    at ChromeLauncher.launch (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:93:37)
    at async handler (/var/task/.next/server/pages/api/getLinkedin.js:27:21)
    at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:372:9)
    at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:488:9)
    at async Object.fn (/var/task/node_modules/next/dist/server/next-server.js:751:37)
    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:253:36)
    at async NextNodeServer.run (/var/task/node_modules/next/dist/server/base-server.js:384:29)
    at async NextNodeServer.handleRequest (/var/task/node_modules/next/dist/server/base-server.js:322:20)
2023-02-02T00:00:23.124Z    7545c99c-ea8f-41d3-8771-97eb786502cb    ERROR   Error: Could not find Chromium (rev. 1083080). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npm install`) or
 2. your cache path is incorrectly configured (which is: /home/sbx_user1051/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
    at ChromeLauncher.resolveExecutablePath (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:127:27)
    at ChromeLauncher.executablePath (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:205:25)
    at ChromeLauncher.launch (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:93:37)
    at async handler (/var/task/.next/server/pages/api/getLinkedin.js:27:21)
    at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:372:9)
    at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:488:9)
    at async Object.fn (/var/task/node_modules/next/dist/server/next-server.js:751:37)
    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:253:36)
    at async NextNodeServer.run (/var/task/node_modules/next/dist/server/base-server.js:384:29)
    at async NextNodeServer.handleRequest (/var/task/node_modules/next/dist/server/base-server.js:322:20)
RequestId: 7545c99c-ea8f-41d3-8771-97eb786502cb Error: Runtime exited with error: exit status 1
Runtime.ExitError

I went to the Puppeteer docs and I changed the config file as shown:

const {join} = require('path');

/**
 * @type {import("puppeteer").Configuration}
 */
module.exports = {
  // Changes the cache location for Puppeteer.
  cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};

That didn't fix it.

qq1o9u81
  • 31
  • 2
  • The error is due chromium version is incompatible with the puppeteer version. checkout: https://pptr.dev/chromium-support – Milind Singh Feb 02 '23 at 13:53
  • 1
    No, it's not. It is because Vercel is a serverless deployment platform (AWS Lambda is the underlying infrastructure). Puppeteer requires an environment with a local chromium binary, which does not exist on AWS Lambda. A common workaround is using the `puppeteer-core` with `chrome-aws-lambda` package, but that solution is currently broken. You actually need to spin up a dedicated box somewhere and let `puppeteer` bundle its own binary. – qq1o9u81 Feb 03 '23 at 17:02
  • Refer: https://github.com/openwishlist/preview/blob/main/src/lib/browser.ts I am using a different maintained library. Also, writing an article, will share in a week. – Milind Singh Feb 03 '23 at 17:37

0 Answers0