【发布时间】:2019-08-07 01:17:55
【问题描述】:
我在 Windows pc 上使用节点版本 10.15.3、npm 版本 6.9.0、VS 代码和 firebase-functions 版本 2.2.0。将 async/await 添加到我的 app.post() 函数会导致:
Function failed on loading user code. Error message: Code in file
index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:31
app.post('/pay-now', async (req, res) => {
^
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at getUserFunction (/var/tmp/worker/worker.js:439:24)
这是我的 app.post():
app.post('/pay-now', async (req, res) => {
// charge user's card
const charge = await makeCharge(req, res)
// store order info in database, returns address of order
const address = await storeOrder(req, res, charge.id)
// send email to customer
await emailHandler.sendCustomerEmail(req, res)
// send email to company letting them know they have a new order
await emailHandler.sendLTEmail(req, res, address, true)
return res.sendStatus(200)
})
我尝试删除 app.post() 中的 async 和 await,但是在函数 makeCharge 中第一次使用 async 时我得到了同样的错误。知道什么可能是错的吗?
【问题讨论】:
-
您是否尝试过删除
node_modules目录后跟npm install?也许您最近更改了节点版本,并且您的模块是使用不同版本构建的? -
你到底做了什么(运行命令?在编辑器中做某事?)使错误出现?
-
@Robbie 刚刚尝试过并得到了相同的结果
-
@DougStevenson 我运行
firebase deploy --only functions
标签: node.js firebase express npm async-await