sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.09k stars 126 forks source link

Running Playwright library #537

Open qe360-vrucenzon opened 2 weeks ago

qe360-vrucenzon commented 2 weeks ago

Hello,

I have a Next.js app that has an API route that uses Playwright library to extract the HTML of a web page. I'm new to deploying Next.js apps and I'm trying to do so with SST Ion. My app works locally, however when I try to deploy it, I get this error from the console logs:

Error: Cannot find module './recorder/csharp' Require stack: - /var/task/node_modules/playwright-core/lib/server/recorder.js - /var/task/node_modules/playwright-core/lib/server/browserContext.js - /var/task/node_modules/playwright-core/lib/server/fetch.js - /var/task/node_modules/playwright-core/lib/server/dispatchers/playwrightDispatcher.js - /var/task/node_modules/playwright-core/lib/server/index.js - /var/task/node_modules/playwright-core/lib/inProcessFactory.js - /var/task/node_modules/playwright-core/lib/inprocess.js - /var/task/node_modules/playwright-core/index.js - /var/task/node_modules/playwright/index.js - /var/task/.next/server/app/api/playwright/route.js - /var/task/node_modules/next/dist/server/require.js - /var/task/node_modules/next/dist/server/next-server.js

I tried creating a clean sample project from scratch to see if it was a problem with my own app, but I encountered the same error as well.

Here's what my sample API route that uses Playwright looks like:

import { chromium } from "playwright";

export async function GET(reqeust: Request) {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  console.log("POSTED!");
  return Response.json({ message: "POSTED!" });
}

Here's my basic SST config:

/// <reference path="./.sst/platform/config.d.ts" />

export default $config({
  app(input) {
    return {
      name: "playwright-test",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
    };
  },
  async run() {
    new sst.aws.Nextjs("MyWeb");
  },
});

I have playwright and @playwright/browser-chromium installed as dependencies.

Is there a way to be able to run Playwright (or browsers in general) on SST Ion?

jayair commented 2 weeks ago

Given that this is within Next.js, I think you might want to ask over on the Open Next side: https://open-next.js.org