我以这种方式导出测试功能:export default test;
const puppeteer = require('puppeteer');
async function test() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
// Get the "viewport" of the page, as reported by the page.
const dimensions = await page.evaluate(() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio
};
});
console.log('Dimensions:', dimensions);
await browser.close();
};
我正在example.js
的上方导入import test from './example'
文件。因为我遇到错误Uncaught Error: Cannot find module 'ws'
at webpackMissingModule (WebSocketTransport.js:16)
at Object../node_modules/puppeteer/lib/WebSocketTransport.js
我安装了ws
,但仍然是相同的错误。
看起来是因为我试图将puppeteer捆绑在Web应用程序中使用。我该怎么解决?