npm安装不成功
npm install puppeteer失败,切换源到中国镜像。
npm config set registry https://registry.npmmirror.com
npm install puppeteer
运行官方案例不成功
官方给出的引入方式,变更成puppeteer。
import puppeteer from 'puppeteer';
// const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://localhost:5173', {waitUntil: 'networkidle2'});
await page.pdf({path: 'hn.pdf', format: 'A4'});
await browser.close();
})();
报错 Warning: To load an ES module, set "type": "module"
(node:19084) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
C:\03 - other\puppeteer\hn.js.js:1
package.json加入type。
{
"type": "module",
"devDependencies": {
"puppeteer": "^23.4.0"
}
}
报错 ReferenceError: ReadableStream is not defined
切换node版本到18.
nvm use 18.20.4
终于能运行了。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。