I have a script that I run with babel-node
and it works with one await
in it, but when I add another await
, it throws a SyntaxError: Unexpected token
error that looks something like this:
SyntaxError: C:/Users/User/Documents/thing/updateFirebase.js: Unexpected token (73:12)
[0m 71 | [31m'votes'[39m[1m:[22m [35m0[39m
72 | [32m}[39m[1m;[22m
> 73 | await writeNewData[94m[1m([22m[39mcard[1m.[22mname[1m,[22m newData[1m,[22m newEditionArrayId[94m[1m)[22m[39m[1m;[22m
| ^
74 | [32m}[39m
75 | [32m}[39m
76 | [36melse[39m [32m{[39m [90m
I'm using Firebase's realtime database and my first await is simply waiting to get a chunk of data:
let snapshot = await dbRef.once('value');
Then I do a bunch of other stuff, go into a loop and do this:
await writeNewData(book.name, newData, newEditionArrayId);
And this is the called function:
function writeNewData(name, object, arrayId) {
var localMidRef = Firebase.database().ref(name + "/editions/"+ arrayId);
console.log("writing new data to "+name);
return localMidRef.set(object);
}
I assume set()
works asynchronously, since you can pass it a callback (I haven't found any documentation in Firebase's docs on it to prove otherwise...). But I can't understand why the damn await keyword screws up the parsing on the second usage, and not the first.
My .babelrc
file:
{
"presets": ["es2015", "react"],
"plugins": ["syntax-async-functions","transform-regenerator"]
}
If I put stage-0
in there it all stops working.
First fix your prompt to show ANSI colors instead of the escape codes, so we don't have to guess where the error was. https://serverfault.com/questions/106028/how-to-enable-ansi-escape-codes-in-windows-cmd
You can also do a simple isolated test with await and babel to make sure that isn't the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.