Amazon web services Cloud9 AWS Lambda中的意外令牌函数
我正在节点为v8.11.3 npm v5.10.0的AWS lambda函数中尝试异步/等待方法。当我运行时,它会给出以下响应:Amazon web services Cloud9 AWS Lambda中的意外令牌函数,amazon-web-services,aws-lambda,aws-cloud9,Amazon Web Services,Aws Lambda,Aws Cloud9,我正在节点为v8.11.3 npm v5.10.0的AWS lambda函数中尝试异步/等待方法。当我运行时,它会给出以下响应: { "errorMessage": "Unexpected token function", "errorType": "SyntaxError", "stackTrace": [ " ^^^^^^^^", "SyntaxError: Unexpected token
{
"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);
}
如何解决此问题?您遇到此错误是因为您正在cloud9环境进程中运行旧版本的nodejs(可以通过
console.log(process.version)
验证,它将不同于节点--version
)。按照以下步骤更新Cloud9环境中的流程节点:
nvm install 11
nvm use 11
nvm alias default v11
删除单词
函数
。