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.










share|improve this question






















  • 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"} into functions/package.json, not package.json?
    – gump
    Nov 20 at 5:31















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.










share|improve this question






















  • 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"} into functions/package.json, not package.json?
    – gump
    Nov 20 at 5:31













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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"} into functions/package.json, not package.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










  • 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"} into functions/package.json, not package.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












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.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    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

























    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.






    share|improve this answer

























      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.






      share|improve this answer























        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 at 22:49









        Paramdeep Singh Obheroi

        319520




        319520






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen