Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: The "serverless-plugin-chrome" plugin only supports the Node.js 6.10 or 8.10 runtimes. Your service is using the "nodejs18.x" provider. #772

Open
QA1980 opened this issue Dec 8, 2023 · 6 comments

Comments

@QA1980
Copy link

QA1980 commented Dec 8, 2023

Environment: linux, node 20.9.0, framework 3.36.0 (local), plugin 7.1.0, SDK 4.4.0
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues

Error:
Error: The "serverless-plugin-chrome" plugin only supports the Node.js 6.10 or 8.10 runtimes. Your service is using the "nodejs18.x" provider.
at throwIfUnsupportedRuntime (/workspace/node_modules/serverless-plugin-chrome/dist/index.js:27:11)
at new ServerlessChrome (/workspace/node_modules/serverless-plugin-chrome/dist/index.js:82:5)
at PluginManager.addPlugin (/workspace/node_modules/serverless/lib/classes/plugin-manager.js:91:28)
at /workspace/node_modules/serverless/lib/classes/plugin-manager.js:137:69
at Array.forEach ()
at PluginManager.loadAllPlugins (/workspace/node_modules/serverless/lib/classes/plugin-manager.js:137:44)
at async Serverless.init (/workspace/node_modules/serverless/lib/serverless.js:146:5)
at async /workspace/node_modules/serverless/scripts/serverless.js:601:7

@ckohtz
Copy link

ckohtz commented Dec 28, 2023

I'm having the same problem.

@muhzak
Copy link

muhzak commented Mar 27, 2024

Same here.

@piyush-kacha
Copy link

I'm facing the same issue

@ckohtz
Copy link

ckohtz commented Jun 3, 2024

@piyush-kacha @muhzak I got around this by not using serverless-plugin-chrome at all. I don't think it's being maintained anymore. Not sure what you're doing, but I ended up using @sparticuz/chromium with puppeteer to create my PDF generator.

@technicalbirdVayuz
Copy link

HI,

Can you share sample for this? sparticuz/chromium also not working

@piyush-kacha @muhzak I got around this by not using serverless-plugin-chrome at all. I don't think it's being maintained anymore. Not sure what you're doing, but I ended up using @sparticuz/chromium with puppeteer to create my PDF generator.

@ckohtz
Copy link

ckohtz commented Jun 11, 2024

Here is a working example using node 18.

Ours runs as a serverless lambda function that we pass values to (ie. the url) and it will save the PDF to an S3 bucket. It includes caching the PDF and a bunch of other features including saving the file locally for testing.

I stripped out everything but the saving locally part to make it less confusing and easier to get running. Just make sure you have a temp directory where you run this, be sure to install the dependencies, and it should work.

//.env
IS_OFFLINE = true
require("dotenv").config();
const chromium = require("@sparticuz/chromium");
const fs = require("fs");
const path = require("path");

// If you're running this as a lambda function, use puppeteer-core
const puppeteer =
  process.env.IS_OFFLINE === "true"
    ? require("puppeteer")
    : require("puppeteer-core");

const pdfGenerator = async () => {
  const url = "http://news.google.com";

  const executablePath =
    process.env.IS_OFFLINE === "true"
      ? undefined
      : await chromium.executablePath();

  chromium.setGraphiceMode = false;
  const browser = await puppeteer.launch({
    args: ["--font-render-hinting=none", ...chromium.args],
    defaultViewport: chromium.defaultViewport,
    executablePath: executablePath,
    headless: chromium.headless,
    ignoreHTTPSErrors: true,
  });

  const page = await browser.newPage();
  await page.goto(url, { waitUntil: "load" });

  const pdfBuffer = await page.pdf({
    printBackground: true,
    preferCSSPageSize: true,
    margin: {
      top: "0px",
      right: "0px",
      bottom: "0px",
      left: "0px",
    },
    waitUntil: "networkidle0",
  });

  const filePath = path.join("./temp", "myFile.pdf");
  fs.writeFileSync(filePath, pdfBuffer);

  console.log("Stored locally at " + filePath);
  process.exit();
};

pdfGenerator();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants