关于puppeteer 启动报 you did not perform an installation before running the script

456 阅读1分钟

用puppeteer搞vue项目的seo,node命令直接运行没有问题,但pm2运行就会报

Error: Could not find Chromium (rev. 1069273). 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: /root/.cache/puppeteer). For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.

我查了半天解决的方法是在项目根目录下 创建

puppeteer.config.js 文件

内容是

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

/**
 * @type {import("puppeteer").Configuration}
 */
module.exports = {
  cacheDirectory: join(__dirname, ".cache", "puppeteer"),
};

官网有具体配置官网文档地址

配置好后直接运行还是会报错

需要卸载掉 puppeteer重新安装就好了