我在应用程序上添加了一个新功能,其中包括在页面的静态道具中使用playwright-aws-lambda
。
当我部署我的应用程序时,我收到以下错误:
Error occurred prerendering page "/url/of/some/page". Read more: https://nextjs.org/docs/messages/prerender-error
at Object.launchChromium (/vercel/path0/node_modules/playwright-aws-lambda/dist/src/chromium.js:97:47)
at async generateOgImage (/vercel/path0/.next/server/pages/blog/[...slug].js:21:21)
at async getStaticProps (/vercel/path0/.next/server/pages/blog/[...slug].js:122:25)
at async renderToHTML (/vercel/path0/node_modules/next/dist/server/render.js:470:20)
at async /vercel/path0/node_modules/next/dist/export/worker.js:253:36
at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
还有一条不是错误或警告的消息,上面写着:
browserType.launch: Executable doesn't exist at /vercel/.cache/ms-playwright/chromium-1019/chrome-linux/chrome
╔═════════════════════════════════════════════════════════════════════════╗
║ Looks like Playwright Test or Playwright was just installed or updated. ║
║ Please run the following command to download new browsers: ║
║ ║
║ npx playwright install ║
║ ║
║ <3 Playwright Team ║
╚═════════════════════════════════════════════════════════════════════════╝
我尝试在我的机器上运行指定的命令,但它对我正在部署的回购没有任何作用。我该如何解决此问题?
我最终通过运行构建脚本中日志中显示的命令来解决这个问题:
// package.json
{
"scripts": {
// ...
"build": "next build && npx playwright install",
},
}
如果我没记错的话,剧作家会有15MB的限制。在您的package.json中,依赖项应该如下所示:
"dependencies": {
"chrome-aws-lambda": "^6",
"express": "^4.18.1",
"playwright-core": "^1.27.1"
},
"devDependencies": {
"playwright": "^1.27.1"
}
这样,在生产中(在aws服务器上运行(,它就使用了轻量级版本。
然而,当我尝试时,我得到了504超时,因为我使用的是一个限制为5秒的免费帐户。我发现Puppeteer更快、更适合这份工作。