question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Helpers missing from output file for a TS script (instead of module)

See original GitHub issue

I get a Uncaught ReferenceError: __awaiter is not defined when compiling a file with async. I’m using the latest TypeScript (2.6.2), rollup (0.53.0) and plugin (0.9.0).

main.ts

async function main() {
}
main();

rollup.config.js

import typescript from 'rollup-plugin-typescript2';

export default {
  output: {
    format: 'iife'
  },
  plugins: [
    typescript()
  ]
}

tsconfig.json

{
  "compilerOptions": {
    "lib": [
      "es2015"
    ]
  }
}

main.js:

(function () {
'use strict';

function main() {
    return __awaiter(this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            return [2 /*return*/];
        });
    });
}
main();

}());

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ezolenkocommented, May 25, 2022

This is in 0.10.0

1reaction
mohd-akramcommented, Dec 26, 2017

I modified rollup-plugin-typescript2.cjs.js in node_modules to remove noEmitHelpers: true and didn’t find any duplicates of __awaiter. I then removed importHelpers: true which caused __awaiter$1 to be added to the output. Both modules had async functions in them.

To test with tsc:

tsc main.ts --importHelpers --module es2015 --lib es2015 --moduleResolution node

main.ts:

import f from './module';

async function main() {
  await f();
}
main();

module.ts:

async function f() {
}
export default f;

main.js:

import * as tslib_1 from "tslib";
import f from './module';
function main() {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, f()];
                case 1:
                    _a.sent();
                    return [2 /*return*/];
            }
        });
    });
}
main();

module.js

import * as tslib_1 from "tslib";
function f() {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        return tslib_1.__generator(this, function (_a) {
            return [2 /*return*/];
        });
    });
}
export default f;
Read more comments on GitHub >

github_iconTop Results From Across the Web

ts is missing from the TypeScript compilation. Please make ...
The @wtw folder is under the node_modules folder. The child project was building the parent package fine when it was in Angular version...
Read more >
TSConfig Reference - Docs on every TSConfig option
A TSConfig file in a directory indicates that the directory is the root of a ... these helper functions are instead imported from...
Read more >
How we employed the new ECMAScript Module Support in ...
Just by adding type after import tells TS this should not be added to the output file. It then just resolves the type...
Read more >
typescript-cheatsheet - GitHub Pages
A set of TypeScript related notes used for quick reference. The cheatsheet contains references to types, classes, decorators, and many other TypeScript ......
Read more >
@rollup/plugin-typescript - npm
rollup.config.js import typescript from '@rollup/plugin-typescript'; export default { input: 'src/index.ts', output: { dir: 'output', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found