How to use await async in firebase cloud function?
up vote
-1
down vote
favorite
I've built a couple of cloud functions in nodejs 6 and now i want to use await
. How do I do that? How can I upgrade to node 8? I don't want to shift to typescript.
I've tried adding "engines": {"node": "8"}
to package.json but it changed nothing.
This is a test cloud function I made:
exports.awaittest = functions.https.onRequest(async (req, res)=>{
ref = await admin.database().ref("/something/");
res.send(ref)
})
when I try to deploy it (with package.json edited), I get this:
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at getUserFunction (/var/tmp/worker/worker.js:413:24)
! functions[awaittest]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:59
exports.awaittest = functions.https.onRequest(async (req, res)=>{
^
How do I upgrade to node8? I already have 6 functions deployed in node6.
node.js firebase asynchronous async-await google-cloud-functions
|
show 1 more comment
up vote
-1
down vote
favorite
I've built a couple of cloud functions in nodejs 6 and now i want to use await
. How do I do that? How can I upgrade to node 8? I don't want to shift to typescript.
I've tried adding "engines": {"node": "8"}
to package.json but it changed nothing.
This is a test cloud function I made:
exports.awaittest = functions.https.onRequest(async (req, res)=>{
ref = await admin.database().ref("/something/");
res.send(ref)
})
when I try to deploy it (with package.json edited), I get this:
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at getUserFunction (/var/tmp/worker/worker.js:413:24)
! functions[awaittest]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:59
exports.awaittest = functions.https.onRequest(async (req, res)=>{
^
How do I upgrade to node8? I already have 6 functions deployed in node6.
node.js firebase asynchronous async-await google-cloud-functions
node.green ... you have to upgrade. Simply npm a upgrade to node or install it directly (windows)
– split
Nov 20 at 1:38
Please edit the question to show the version of the CLI you're using, and proof that your function deployed to node 8 (it will be in the output). Also you should know that TypeScript is a strict superset of JavaScript, so all your JavaScript will just keep working if you just copy it over to TS.
– Doug Stevenson
Nov 20 at 1:46
I am not with my laptop rn but I have ensured that all my tools and framework are up-to-date. If you think I should shift to typescript, please do tell me how to migrate my project to ts.
– Paramdeep Singh Obheroi
Nov 20 at 1:48
You also need to be using Node.js 8 on your local machine, or the CLI will have parse errors when trying to extract trigger information from your code.
– Michael Bleigh
Nov 20 at 2:11
Can you make sure adding"engines": {"node": "8"}
intofunctions/package.json
, notpackage.json
?
– gump
Nov 20 at 5:31
|
show 1 more comment
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I've built a couple of cloud functions in nodejs 6 and now i want to use await
. How do I do that? How can I upgrade to node 8? I don't want to shift to typescript.
I've tried adding "engines": {"node": "8"}
to package.json but it changed nothing.
This is a test cloud function I made:
exports.awaittest = functions.https.onRequest(async (req, res)=>{
ref = await admin.database().ref("/something/");
res.send(ref)
})
when I try to deploy it (with package.json edited), I get this:
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at getUserFunction (/var/tmp/worker/worker.js:413:24)
! functions[awaittest]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:59
exports.awaittest = functions.https.onRequest(async (req, res)=>{
^
How do I upgrade to node8? I already have 6 functions deployed in node6.
node.js firebase asynchronous async-await google-cloud-functions
I've built a couple of cloud functions in nodejs 6 and now i want to use await
. How do I do that? How can I upgrade to node 8? I don't want to shift to typescript.
I've tried adding "engines": {"node": "8"}
to package.json but it changed nothing.
This is a test cloud function I made:
exports.awaittest = functions.https.onRequest(async (req, res)=>{
ref = await admin.database().ref("/something/");
res.send(ref)
})
when I try to deploy it (with package.json edited), I get this:
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at getUserFunction (/var/tmp/worker/worker.js:413:24)
! functions[awaittest]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:59
exports.awaittest = functions.https.onRequest(async (req, res)=>{
^
How do I upgrade to node8? I already have 6 functions deployed in node6.
node.js firebase asynchronous async-await google-cloud-functions
node.js firebase asynchronous async-await google-cloud-functions
asked Nov 20 at 1:21
Paramdeep Singh Obheroi
319520
319520
node.green ... you have to upgrade. Simply npm a upgrade to node or install it directly (windows)
– split
Nov 20 at 1:38
Please edit the question to show the version of the CLI you're using, and proof that your function deployed to node 8 (it will be in the output). Also you should know that TypeScript is a strict superset of JavaScript, so all your JavaScript will just keep working if you just copy it over to TS.
– Doug Stevenson
Nov 20 at 1:46
I am not with my laptop rn but I have ensured that all my tools and framework are up-to-date. If you think I should shift to typescript, please do tell me how to migrate my project to ts.
– Paramdeep Singh Obheroi
Nov 20 at 1:48
You also need to be using Node.js 8 on your local machine, or the CLI will have parse errors when trying to extract trigger information from your code.
– Michael Bleigh
Nov 20 at 2:11
Can you make sure adding"engines": {"node": "8"}
intofunctions/package.json
, notpackage.json
?
– gump
Nov 20 at 5:31
|
show 1 more comment
node.green ... you have to upgrade. Simply npm a upgrade to node or install it directly (windows)
– split
Nov 20 at 1:38
Please edit the question to show the version of the CLI you're using, and proof that your function deployed to node 8 (it will be in the output). Also you should know that TypeScript is a strict superset of JavaScript, so all your JavaScript will just keep working if you just copy it over to TS.
– Doug Stevenson
Nov 20 at 1:46
I am not with my laptop rn but I have ensured that all my tools and framework are up-to-date. If you think I should shift to typescript, please do tell me how to migrate my project to ts.
– Paramdeep Singh Obheroi
Nov 20 at 1:48
You also need to be using Node.js 8 on your local machine, or the CLI will have parse errors when trying to extract trigger information from your code.
– Michael Bleigh
Nov 20 at 2:11
Can you make sure adding"engines": {"node": "8"}
intofunctions/package.json
, notpackage.json
?
– gump
Nov 20 at 5:31
node.green ... you have to upgrade. Simply npm a upgrade to node or install it directly (windows)
– split
Nov 20 at 1:38
node.green ... you have to upgrade. Simply npm a upgrade to node or install it directly (windows)
– split
Nov 20 at 1:38
Please edit the question to show the version of the CLI you're using, and proof that your function deployed to node 8 (it will be in the output). Also you should know that TypeScript is a strict superset of JavaScript, so all your JavaScript will just keep working if you just copy it over to TS.
– Doug Stevenson
Nov 20 at 1:46
Please edit the question to show the version of the CLI you're using, and proof that your function deployed to node 8 (it will be in the output). Also you should know that TypeScript is a strict superset of JavaScript, so all your JavaScript will just keep working if you just copy it over to TS.
– Doug Stevenson
Nov 20 at 1:46
I am not with my laptop rn but I have ensured that all my tools and framework are up-to-date. If you think I should shift to typescript, please do tell me how to migrate my project to ts.
– Paramdeep Singh Obheroi
Nov 20 at 1:48
I am not with my laptop rn but I have ensured that all my tools and framework are up-to-date. If you think I should shift to typescript, please do tell me how to migrate my project to ts.
– Paramdeep Singh Obheroi
Nov 20 at 1:48
You also need to be using Node.js 8 on your local machine, or the CLI will have parse errors when trying to extract trigger information from your code.
– Michael Bleigh
Nov 20 at 2:11
You also need to be using Node.js 8 on your local machine, or the CLI will have parse errors when trying to extract trigger information from your code.
– Michael Bleigh
Nov 20 at 2:11
Can you make sure adding
"engines": {"node": "8"}
into functions/package.json
, not package.json
?– gump
Nov 20 at 5:31
Can you make sure adding
"engines": {"node": "8"}
into functions/package.json
, not package.json
?– gump
Nov 20 at 5:31
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
-1
down vote
accepted
Okay I solved it. I had to first remove my older cloud functions via Google Cloud console, updated firebase-tools
and then re-deployed everything with "engines": {"node": "8"}
added to functions/package.json
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
-1
down vote
accepted
Okay I solved it. I had to first remove my older cloud functions via Google Cloud console, updated firebase-tools
and then re-deployed everything with "engines": {"node": "8"}
added to functions/package.json
.
add a comment |
up vote
-1
down vote
accepted
Okay I solved it. I had to first remove my older cloud functions via Google Cloud console, updated firebase-tools
and then re-deployed everything with "engines": {"node": "8"}
added to functions/package.json
.
add a comment |
up vote
-1
down vote
accepted
up vote
-1
down vote
accepted
Okay I solved it. I had to first remove my older cloud functions via Google Cloud console, updated firebase-tools
and then re-deployed everything with "engines": {"node": "8"}
added to functions/package.json
.
Okay I solved it. I had to first remove my older cloud functions via Google Cloud console, updated firebase-tools
and then re-deployed everything with "engines": {"node": "8"}
added to functions/package.json
.
answered Nov 20 at 22:49
Paramdeep Singh Obheroi
319520
319520
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384916%2fhow-to-use-await-async-in-firebase-cloud-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
node.green ... you have to upgrade. Simply npm a upgrade to node or install it directly (windows)
– split
Nov 20 at 1:38
Please edit the question to show the version of the CLI you're using, and proof that your function deployed to node 8 (it will be in the output). Also you should know that TypeScript is a strict superset of JavaScript, so all your JavaScript will just keep working if you just copy it over to TS.
– Doug Stevenson
Nov 20 at 1:46
I am not with my laptop rn but I have ensured that all my tools and framework are up-to-date. If you think I should shift to typescript, please do tell me how to migrate my project to ts.
– Paramdeep Singh Obheroi
Nov 20 at 1:48
You also need to be using Node.js 8 on your local machine, or the CLI will have parse errors when trying to extract trigger information from your code.
– Michael Bleigh
Nov 20 at 2:11
Can you make sure adding
"engines": {"node": "8"}
intofunctions/package.json
, notpackage.json
?– gump
Nov 20 at 5:31