我有一个express设置。由于某些原因,此函数未能识别req:
router.post('/search', (req, res) => {
;(async (req, res) => { //req and res here are just parameters in function definition
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(`https://www.google.com/search?tbm=bks&q=%22this+is%22`)
const result = await page.evaluate(() => {
console.log('CLAUSESS:', req.body.clauses)
const clauses = req.body.clauses
return clauses.map(clause => clause.textContent)
})
result.join('\n')
await browser.close()
res.send(result)
})(req,res); //This is where we call the function, so we need to pass the actual values here.
})
这是错误消息:
UnhandledPromiseRejectionWarning: 没有处理的 promise 拒绝 (拒绝 ID: 1): 错误: 评估失败: ReferenceError: req 未定义 at :2:32
可能的原因是什么?
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Evaluation failed: ReferenceError: req is not defined at <anonymous>:2:32
- alexIncomingMessage {_readableState: ReadableState {
,所以我认为它存在那里。 - alex