Skip to content

Emit for dynamic import (import()) when target >= ES2020 and module == None #48702

Closed
@rbuckton

Description

@rbuckton

Bug Report

We unconditionally transform dynamic import (import()) regardless of the current script target when the module kind is None. This is due to us using the CommonJS module emit as a fallback for None, and is causing an issue for VSCode while trying to implement support for TS Server plugins on the web via WebWorker.

I propose that we change the emit behavior for import() when the module target is None to preserve import(). Note that this would constitute a breaking change, but I imagine the number of affected projects (those currently using both --module None and import()) would be vanishingly small.

🔎 Search Terms

dynamic import module none node transform emit outFile

⏯ Playground Link

Playground link with relevant code

💻 Code

// @target: es2020
// @module: none
// @outFile: foo.js
const foo = import("foo");

🙁 Actual behavior

Transforms import() into a call to require()

🙂 Expected behavior

Does not transform import().

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions