Skip to content

importHelpers does not emit import unless at least one other import is present #12167

Closed

Description

Noticed on a webpack project with typescript@2.1.1, using either commonjs or es2015 modules:

// index.ts

import './empty'

async function x () {}
// empty.ts

This emits an import for tslib following by the import for empty. However, commenting the import 'empty' line out also omits the import for tslib, and the emitted code attempts to use a global __awaiter.

I thought this might have been fixed by #12151, but it's still present in current master (built with gulp LKG).

Activity

  1. changed the title [-]importHelpers does not emit import if not at least one other import is present[/-] [+]importHelpers does not emit import unless at least one other import is present[/+] on Nov 11, 2016
  2. Jessidhia commented on Nov 11, 2016

    @Jessidhia
    Author

    Using isolatedModules gives a clue: the "Cannot compile namespaces" error hints that tsc doesn't/can't treat files without import/export as a module.

    With isolatedModules enabled, putting an export {} is enough to pass the isolatedModules condition, and the code is emitted with the tslib import.

  3. Checksum commented on Jan 10, 2017

    @Checksum

    Just wasted two hours on this! With an empty import statement, it works as intended. Tested on version 2.2.0-dev.20170110

  4. mhegazy commented on Jan 21, 2017

    @mhegazy
    Contributor

    If the file does not have a toplevel import/export is it is not considered a module, and it is treated as script/global.

    use --isolatedModules to flag these files as errors.

  5. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions