我正在尝试在页面评估中提出两个请求 但我得到
Error: Evaluation failed: ReferenceError: __awaiter is not define at __puppeteer_evaluation_script
我有一个名为app.ts
的文件:
public async main() {
this.browser = await puppeteer.launch({
headless: config.get("puppeteer.headless"),
args: config.get("puppeteer.args")
});
this.page = await this.browser.newPage();
await this.page.evaluate(async () => {
fetch("https://www.npmjs.com/features").then(response => response.text()).then(
html => console.log(" Log within page"))
}).catch(error => console.log(error));
}
我得到的错误是:
Error: Evaluation failed: ReferenceError: __awaiter is not defined
at __puppeteer_evaluation_script__:1:16
at ExecutionContext.evaluateHandle (/home/pap/Desktop/nodejs-project/node_modules/puppeteer/lib/ExecutionContext.js:124:13)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
-- ASYNC --
at ExecutionContext.<anonymous> (/home/pap/Desktop/nodejs-project/node_modules/puppeteer/lib/helper.js:144:27)
at ExecutionContext.evaluate (/home/pap/Desktop/nodejs-project/node_modules/puppeteer/lib/ExecutionContext.js:58:31)
at ExecutionContext.<anonymous> (/home/pap/Desktop/nodejs-project/node_modules/puppeteer/lib/helper.js:145:23)
at Frame.evaluate (/home/pap/Desktop/nodejs-project/node_modules/puppeteer/lib/FrameManager.js:439:20)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
-- ASYNC --
at Frame.<anonymous> (/home/pap/Desktop/nodejs-project/node_modules/puppeteer/lib/helper.js:144:27)
at Page.evaluate (/home/pap/Desktop/nodejs-project/node_modules/puppeteer/lib/Page.js:736:43)
at Page.<anonymous> (/home/pap/Desktop/nodejs-project/node_modules/puppeteer/lib/helper.js:145:23)
at app.<anonymous> (/home/pap/Desktop/nodejs-project/app.js:209:51)
at step (/home/pap/Desktop/nodejs-project/app.js:32:23)
at Object.next (/home/pap/Desktop/nodejs-project/app.js:13:53)
at fulfilled (/home/pap/Desktop/nodejs-project/app.js:4:58)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
我尝试在添加"noEmitHelpers": false
的ts配置中解决此问题,但仍未解决。尝试过importHelpers": true
,但仍然遇到相同的问题。有帮助吗?
我的ts配置文件如下所示:
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmitHelpers": false,
"strictNullChecks": false,
"typeRoots": [
"node_modules/@types"
]
},
"compileOnSave": true,
"exclude": [
"dist",
"node_modules"
]
}
我使用ts app.ts