Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function is not defined when using async function using babel and Typescript in development #63

Open
buzzin0609 opened this issue Apr 20, 2020 · 1 comment

Comments

@buzzin0609
Copy link

Hi,

I'm using Babel and Typescript in development, which I compile to JS for production. However, when trying to use microjob with an async function working locally I get a _functionName is not defined error.
Here is some simple code to reproduce:

//index.ts
import express from "express";
import {job, start} from "microjob";

const app = express();

app.get("/", async function(req: express.Request, res: express.Response) {
    await start();

    const test = async () => {
        return 'test';
    }

    // all the below fail with the async before the function name above
    // const result = await job(test);
    // const result = await job(() => {
    //     return test();
    // }, { ctx: { test }});
    const result = await job(async () => {
        return test();
    }, { ctx: { test }});
    // const result = await job(async () => {
    //     const response = await test();
    //     return response;
    // }, { ctx: { test }});

    res.send(result);
});

const port = 4790;
app.listen(port);
console.log(`view app at http://localhost:${port}`);

My package.json:

{
  "name": "test-microjob",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "dependencies": {
    "@babel/core": "^7.9.0",
    "@babel/node": "^7.8.7",
    "@babel/plugin-transform-runtime": "^7.9.0",
    "@babel/preset-env": "^7.9.5",
    "@babel/preset-typescript": "^7.9.0",
    "babel-watch": "^7.0.0",
    "express": "^4.17.1",
    "microjob": "^0.7.0"
  },
  "devDependencies": {
    "@types/express": "^4.17.6"
  },
  "scripts": {
    "start": "babel-watch --inspect --extensions \".ts\" index.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

.babelrc

{
  "presets": ["@babel/env","@babel/preset-typescript"],
  "plugins": [
    "@babel/plugin-transform-runtime"
  ]
}

My tsconfig.json

{
  "compilerOptions": {
    "target": "es2017",
    "allowJs": true,
    "skipLibCheck": false,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "isolatedModules": false,
    "jsx": "preserve",
    "outDir": "./build",
    "sourceMap": true
  },
  "include": [
    "index.ts"
  ]
}

Node version 12.6.2

To note: Using an async function passed

Thanks for any help in advance 👍

@usein-abilev
Copy link

Try to change your target parameter to "ES2020" in the tsconfig.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants