Skip to content

Entry points fail without import/export statements #357

@bisubus

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions