Skip to content

Entry points fail without import/export statements #357

Closed

Description

@bisubus

For files that don't have import or export statements ts-node test.ts fails when there is await function:

ReferenceError: __awaiter is not defined

test.ts

(async () => {})().catch(console.error);

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true,
    "sourceMap": true,
    "noEmitHelpers": true,
    "importHelpers": true,
    "strictNullChecks": false,
    "baseUrl": ".",
    "paths": [],
    "lib": [ "es2017"]
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

Of course, tslib is installed. And it starts working normally when export default {} is added.

It was different in older ts-node before it was updated (likely 2.x), an error appeared for all module-scoped const:

Cannot redeclare block-scoped variable ...

And it disappeared when import or export statements were added, so it looks like a file wasn't compiled as ES6 module.

ts-node 3.0.4,
typescript 2.3.4
tslib 1.7.1
node 6.10.3

Activity

  1. blakeembrey commented on Jun 15, 2017

    @blakeembrey
    Member

    This isn't an issue with ts-node. Most likely the different issues have appeared or disappeared based on you updating external factors such as TypeScript or node.js. If I compile using tsc, there's no error from TypeScript and I can easily see why this is an error:

    "use strict";
    (() => __awaiter(this, void 0, void 0, function* () { }))().catch(console.error);
    //# sourceMappingURL=test.js.map
  2. bisubus commented on Jun 15, 2017

    @bisubus
    Author

    @blakeembrey Thanks for the clarification, it makes sense. I've encountered some mentions of this TS trait like microsoft/TypeScript#12167 , still looks obscure and bug-like.

  3. blakeembrey commented on Jun 15, 2017

    @blakeembrey
    Member

    It's unfortunate though. You'd think TypeScript would flag this as an error, but I suppose "technically" you did ask for noEmitHelpers and importHelpers doesn't make sense for a global script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions