Auth0 Home Blog Docs

Async/Await Not Working in Webtask Editor

webtask

#1

Yo,

I’m building a Webtask using the Editor with Node 8, and I’m having trouble getting async/await to run properly. (I’m including “use latest” at the top of my webtask)

I’m getting a "regeneratorRuntime is not defined" error when I run my webtask. I did some research and found this open topic regarding the same issue using the wt-cli.

What’s the deal here? I thought async/await had built-in support since Node 7.6?

Am I missing something?


#2

Hi Shawn

Can you try not using “use latest” to see if that works? There may be an issue related to our babel config / It may not support async/await currently.


#3

Removing “use latest” worked, and I’m no longer getting an error.

Thanks Glenn!


#4

Great. I am glad to hear that worked!


#5

I am facing this issue and I have tried many things and none of them are working. I commented out ‘use latest’, but now I am getting this error message when I run:
{
“code”: 400,
“message”: “Compilation failed: Unexpected token import”,
“error”: “Unexpected token import”,
“stack”: "/data/io/1da03a3c-3ba5-4f8a-83a7-3e832f2cc743/webtask.js:3\nimport express from ‘express’;\n^^^^^^\n\nSyntaxError: Unexpected token import\n at createScript (vm.js:80:10)\n at Object.runInThisContext (vm.js:139:10)\n at WebtaskModule.compileWebtask (/data/sandbox/lib/module.js:91:32)\n at defaultJavascriptCompiler (/data/sandbox/lib/compiler.js:119:30)\n at defaultCompiler (/data/sandbox/lib/compiler.js:128:16)\n at /data/sandbox/lib/compiler.js:231:17\n at /data/sandbox/node_modules/async/dist/async.js:3880:24\n at replenish …

Would appreciate if someone can recommend a fix. Thanks.

I will include my code here if that helps:

import express from ‘express’;
import { fromExpress } from ‘webtask-tools’;
import stripe from ‘stripe’;

var app = express();

// Retrieve all products.

app.get(’/products’, async (req, res) => {
var ctx = req.webtaskContext;
var STRIPE_SECRET_KEY = ctx.secrets.STRIPE_SECRET_KEY;

res.json(await stripe(STRIPE_SECRET_KEY).products.list());

});

module.exports = fromExpress(app);


#6

Using import is currently not natively supported in Node 8. So as of now you still need to use require when importing modules, i.e const express = require('express');


#8