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

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

Closed
Jessidhia opened this issue Nov 11, 2016 · 3 comments
Closed
Labels
Question An issue which isn't directly actionable in code

Comments

@Jessidhia
Copy link

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).

@Jessidhia Jessidhia 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 Nov 11, 2016
@Jessidhia
Copy link
Author

Jessidhia commented Nov 11, 2016

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.

@Checksum
Copy link

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

@mhegazy
Copy link
Contributor

mhegazy commented Jan 21, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants