Javascript SyntaxError:意外的保留字,用于等待循环
我有这样一个函数:Javascript SyntaxError:意外的保留字,用于等待循环,javascript,node.js,google-cloud-functions,Javascript,Node.js,Google Cloud Functions,我有这样一个函数: exports.deleteUser = functions.https.onCall(async(data, context) => { let id = context.auth.uid; console.log('Delete user: ' + id); //delete from algolia usersIndex.deleteObject(id); console.log(id + 'Deleted from al
exports.deleteUser = functions.https.onCall(async(data, context) => {
let id = context.auth.uid;
console.log('Delete user: ' + id);
//delete from algolia
usersIndex.deleteObject(id);
console.log(id + 'Deleted from algolia');
//delete user following
await admin.firestore().collection('users').doc(id).collection('Following').get()
.then(async(snapshot) => {
for await (const document of snapshot.docs) {
await admin.firestore().collection('users').doc(document.documentId)
.update({
'NumberOfFollowers': FieldValue.increment(-1)
});
await admin.firestore().collection('users').doc(document.documentId).collection('Followers')
.doc(id).delete();
}
return console.log('Following of ' + id + ' deleted');
});
...
但是,当我尝试将其部署到firebase函数时,出现了以下错误:
! functions[deleteUser(us-central1)]: Deployment error.
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: /srv/index.js:47
for await (const document of snapshot.docs) {
^^^^^
SyntaxError: Unexpected reserved word
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at getUserFunction (/worker/worker.js:439:24)
发现:但我确实在异步函数中设置了ForLoop…。您可能正在本地或package.json中使用早期的节点版本
您需要确保在用于部署的两个本地节点中至少使用了节点10:
$ node --version
...should print 10.x.x or later
"engines": {
"node": "10"
}
并且还要将目标节点10放在package.json中,以便告诉云函数使用哪个版本进行部署:
$ node --version
...should print 10.x.x or later
"engines": {
"node": "10"
}
使用以下命令来破解解决方案
nvm use lists //if nvm is installed it is useful to check versions of node
node -v // to check which version is getting used
如果node的版本低于10.x.x,则在nvm的帮助下,我们可以使用以下命令指向高于10.x.x的其他版本:
nvm use 12.19.0 //in my case, I have option for latest one as it was installed using nvm install 12.19.0
注意:安装nvm可轻松切换节点版本,无需查看所有代码即可了解可能受影响的内容,这是不可能知道的。试试看它是否管用。我想你不太可能有问题。是的,这是一个拉西问题,我升级没有问题,谢谢