The Wayback Machine - https://web.archive.org/web/20250527182520/https://github.com/microsoft/TypeScript/issues/42371
Skip to content

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

Closed
@anatawa12

Description

@anatawa12

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions