In programming, syntax is considered as a tool to determine whether the combined sequence is in the correct order or not. And from that string, is it possible to build a complete structure for the application being designed? Syntax is like a language bridge between programmers and computers.
If in the process you get a SyntaxError: Unexpected reserved word, for await loop like below, and have tried many ways but it doesn’t work, please refer to our solution!
SyntaxError “Unexpected reserved word, for await loop”
If you have a function that needs to be implemented for firebase functions like below:
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'); }); ...
but you got this error while you have installed ForLoop in an async function:
! 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)
and here is our solution.
Solution
Most likely, in this case you are using an old node version in package.json or locally. To be able to work properly, you need to make sure both your local node that you use for deployment use at least node 10.
For example:
$ node --version ...should print 10.x.x or later
and pay attention to node 10 in your package.json to know which version to use for deployment by Cloud Functions
"engines": { "node": "10" }
Conclusion
Through this tutorial, you learned how to identify errors SyntaxError: Unexpected reserved word, for await loop and how to fix them. Don’t panic if you encounter it, calmly find out the cause and solve it, it will help you gain more understanding in web programming.
Related articles
- Top Ways To Create A User-Friendly Online Property Search For Your Real Estate Clients
If you’re running a real estate business, you’re well aware that pretty much most of the paperwork has become automated and it’s time for you really get an education on what you need to use in terms of technology. This is important to make your online presence and services stand out from the competition. Like […]
- List Education Websites for Students, providing a variety of materials and completely free
Everyone would like to get the highest quality of education in order to fulfill their goals. But the more an institution is of high quality and reputable, the more fees they charge. Students typically leave their education in a state of nil and work blue collar jobs to achieve their primary needs. Additionally, they collect […]
- Simple solution to correct the requests.exceptions.ConnectionError: (‘Connection aborted.’ RemoteDisconnected(‘Remote end closed connection without response’)) issue
Python is a popular programming language that can be used widely in a lot of applications. Python is also a good choice as a programming language depending on user background and perspective. Because it is used widely and popular, if you find any errors when using Python. It is a common problem, you face the […]
- “[Errno 61] Connection refused” is occurring even, the program is connecting with the port well and the socket is running in the interfaces.
If you see the “[Errno 61] Connection refused” issue although you checked the program, port, socket and interfaces. Although your program of Python works well in the server and the client, they are installed at the same device. The local IP from my device is connecting with the clients but this IP is not connected […]
- Description “Return by Reference”.
C++ is considered not only as a language of Object Oriented Programming, but also an intermediate level language. It identifies both high and low level languages. It became easy and widely used in computer programs and that is the reason why we should understand the definition and its function as well. Such as Return by […]