Skip to content

Empty exports #44040

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

Closed
Vardner opened this issue May 11, 2021 · 4 comments
Closed

Empty exports #44040

Vardner opened this issue May 11, 2021 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@Vardner
Copy link

Vardner commented May 11, 2021

Bug Report

πŸ”Ž Search Terms

prevent empty exports {} Object.defineProperty(exports, "__esModule", { value: true });

πŸ•— Version & Regression Information

  • This is a crash
  • This changed between versions 3.9.6 and 4.2.4

⏯ Playground Link

Playground link with relevant code, change typescript version between 3.9.4 and 4+

πŸ’» Code

import {ABC} from './abc';
const a = 12;

πŸ™ Actual behavior

image

πŸ™‚ Expected behavior

image

Hello, I have some problems when typescript generates empty exports in each file by itself. I use TS compiler to generate files that will be executed by eval. When eval happens I get an error because of exports.
In typescript config, we have the option "isolatedModules", which could do this part of the functionality.

Anyway, how can I get rid of any kind of exports in complied files? I hope you can help me because these exports force me to call string.replace() before executing the files!

@nmain
Copy link

nmain commented May 11, 2021

When you type import {ABC} from './abc'; you're using es modules syntax and so Typescript is processing your code as an es module. It's producing output that's also es modules because of your compiler module setting. Depending on what your runtime environment looks like, you could either change the compiler's module setting, or use some sort of bundler, but what you're asking to do just doesn't work out of the box -- you can't eval an es module.

@MartinJohns
Copy link
Contributor

See also #41567, #41562, #41513.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 11, 2021
@Vardner
Copy link
Author

Vardner commented May 12, 2021

When you type import {ABC} from './abc'; you're using es modules syntax and so Typescript is processing your code as an es module. It's producing output that's also es modules because of your compiler module setting. Depending on what your runtime environment looks like, you could either change the compiler's module setting, or use some sort of bundler, but what you're asking to do just doesn't work out of the box -- you can't eval an es module.

yea, of course, but I use imports only for types and interfaces, so none of my files intend to be modules

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants