async function does not work in a plugin


  • Swedes

    This code works with plain nodejs but not when I have it in a plugin!

    async function f3() {
    
      let Parser = require('rss-parser');
      let parser = new Parser();
      let feed = await parser.parseURL('http://www.fz.se/core/rss/fznews_rss20.xml').catch((err) => { console.error(err); });
      console.log(feed);
    }
    
    f3();
    

    Why do I get this error?

    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]: 2018-08-23T14:35:59.849Z [543] - error: /server/nodejs/node_modules/nodebb-widget-rss/plugin.js:40
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]: async function f3() {
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:       ^^^^^^^^
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]: SyntaxError: Unexpected token function
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at createScript (vm.js:56:10)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at Object.runInThisContext (vm.js:97:10)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at Module._compile (module.js:542:28)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at Object.Module._extensions..js (module.js:579:10)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at Module.load (module.js:487:32)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at tryModuleLoad (module.js:446:12)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at Function.Module._load (module.js:438:3)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at Module.require (module.js:497:17)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at require (internal/module.js:20:19)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at Object.Plugins.requireLibrary (/server/nodejs/src/plugins.js:43:32)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at registerHooks (/server/nodejs/src/plugins/load.js:183:13)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at /server/nodejs/src/plugins/load.js:141:6
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at /server/nodejs/node_modules/async/dist/async.js:3880:24
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at eachOfArrayLike (/server/nodejs/node_modules/async/dist/async.js:1069:9)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at eachOf (/server/nodejs/node_modules/async/dist/async.js:1117:5)
    Aug 23 16:35:59 nimbus.jenkler.se docker[23082]:     at _parallel (/server/nodejs/node_modules/async/dist/async.js:3879:5)
    

    Any tips would be great!


  • Swedes

    I am running nodejs v6.11.5.

    Async functions are not supported by Node versions older than version 7.6. 🙂 So, Need to update!


  • Global Moderator

    I suggest updating to the latest LTS (Node 10)


  • Swedes

    Latest LTS is 8.x not 10.x

    https://nodejs.org/en/ <-- Check here

    I will be updating to 8.x. Do we have a lot of issues with mongodb 3.6.x ???? Safe to update?


  • Global Moderator

    Yeah, but Node 10 will be LTS starting in October, so you may as well upgrade to it now.


  • Swedes

    Hehe, true true 😉


  • Swedes

    Works great in 8.x now 😉


 

Suggested Topics

| |