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

TS defines __esModule of exports even if all imports are 'import type' #42371

Closed
anatawa12 opened this issue Jan 16, 2021 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@anatawa12
Copy link

Bug (or bad specification) Report

If some doesn't have 'import', the tsc doesn't generate Object.defineProperty(exports, "__esModule", { value: true });.

import type looks standing for not generating import or code for module system in js but currently Object.defineProperty(exports, "__esModule", { value: true }); is generated.

🔎 Search Terms

In issues and on Google searched with '__esModule import type' and '__esModule generated even if import type'

🕗 Version & Regression Information

typescript: 4.1.3

  • This is not a crash

⏯ Playground Link

Please ignore the compile error. I don't know what module can I use on the playground.

Playground link with relevant code

💻 Code

import type * as something from "<any path>";
{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitAny": true,
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*"]
    },
    "target": "ES2019",
    "moduleResolution": "node"
  },
  "include": [
    "src/**/*"
  ]
}

🙁 Actual behavior

exports code below:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

🙂 Expected behavior

exports code below:

"use strict";

This can be a problem if I want to write ts without tools like WebPack.

@MartinJohns
Copy link
Contributor

MartinJohns commented Jan 16, 2021

I'm pretty sure this is the same as #41513. By having an import statement you're making your file a module, and as a result you have a related exports statement in your compiled file. This behavior was introduced with 4.0, and the old behavior in TypeScript 3.9 is considered a bug.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 20, 2021
@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

4 participants