Fix the Error “SyntaxError: Unexpected reserved word ‘await’”

When you are working with JavaScript programs, it is normal to have encountered errors. As it is a versatile language, there are infinite projects that programmers and developers are working on. Beginners are also practicing various projects to become a pro in JavaScript programming. You may encounter the exception “SyntaxError: Unexpected reserved word ‘await’”.

We provide you with valuable yet simple to execute solutions to help you get rid of the error warning. Let’s check out how the error occurs

How the error pops up

The error occurs when you execute the firebase function. Have a look at the program code

exports.deleteUser = functions.https.onCall(async(data, context) => {
let id = context.auth.uid;
console.log('Delete user: ' + id);

//delete from algolia
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 {
await admin.firestore().collection('users').doc(document.documentId)
'NumberOfFollowers': FieldValue.increment(-1)
await admin.firestore().collection('users').doc(document.documentId).collection('Followers')
return console.log('Following of ' + id + ' deleted');

After executing the program, you get the error like this:

! 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 {

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)

How to Fix the Error “SyntaxError: Unexpected reserved word ‘await’”

The cause of the error is the use of ‘await’ keyword inside a function that was not in asynchronous mode. In order to use it within an operation, you need to ensure to do function marking, which is encircled by the async function.

Check out the solutions to fix the error

Solution 1 – Declare async()

To remove the error, the await function needs to work properly. For this, you need to declare the async function. Use the following code

const functionReturningPromise = (input) => {
return new Promise((resolve, reject) => {
if (!input) {
return reject();

return resolve();

const functionAwaitingPromise = async () => {
for (let i = 0; i < 20; i +=1) {
try {
await functionReturningPromise(i);

} catch (error) {

Solution 2 – Confirm the package.json version

You probably end up with the error warning if you are using an older version of the node in package.json or locally. To avoid the error warning, make sure to at least have node 10. To confirm which version you have, follow the below code

"engines": {
    "node": "10"

To check if you have a local node, follow the below command

$ node --version
...should print 10.x.x or later


We have discussed how to solve the error “SyntaxError: Unexpected reserved word ‘await’”. The solutions we mentioned fix the error.

I hope you find it helpful!

Reference Source:

Leave a Reply

Your email address will not be published. Required fields are marked *