我正在使用节点 v8.11.3 npm v5.10.0 在 AWS lambda 函数中尝试异步/等待方法。当我运行它时,它会给我以下响应:
{
"errorMessage": "Unexpected token function",
"errorType": "SyntaxError",
"stackTrace": [
" ^^^^^^^^",
"SyntaxError: Unexpected token function",
"createScript (vm.js:56:10)",
"Object.runInThisContext (vm.js:97:10)",
"Module._compile (module.js:542:28)",
"Object.Module._extensions..js (module.js:579:10)",
"Module.load (module.js:487:32)",
"tryModuleLoad (module.js:446:12)",
"Function.Module._load (module.js:438:3)",
"Module.require (module.js:497:17)",
"require (internal/module.js:20:19)"
]
}
lambda函数是:
const fetch = require('node-fetch')
exports.handler = async function(event,context)
{
console.log(event);
let img = await
fetch(`https://catappapi.herokuapp.com/users/${event.userId}`);
let parseddata = await img.json()
console.log(parseddata.imageUrl);
}
如何解决这个问题?