Skip to content

[V6] module defaults is not esnextΒ #63330

Open
microsoft/TypeScript-Website
#3608

Description

πŸ”Ž Search Terms

"module", "default", "esnext", "v6"

πŸ•— Version & Regression Information

This changed between versions V5 and V6

⏯ Playground Link

This isn't an issue in Playground, because you're required to enter a value for the module.

https://www.typescriptlang.org/play/?#code/FASwtgDg9gTgLgAgGZSsmUwIEQDoD0KUuAVgM5QB22CA7iHABYIDeCcAnhAKYBcO5KjQC+AbmDAAxlQoAbbrllQA5gAoiASlFA

πŸ’» Code

  • package.json

    {
      "name": "testcase",
      "version": "1.0.0",
      "type": "module",
      "dependencies": {
        "typescript": "6.0.2"
      }
    }
  • index.ts

    import foo from "./foo.json" with { type: "json" };
    
    console.log(foo);
  1. npm install
  2. npc tsc index.ts

πŸ™ Actual behavior

index.ts:1:30 - error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.

1 import foo from "./foo.json" with { type: "json" };
                               ~~~~~~~~~~~~~~~~~~~~~

πŸ™‚ Expected behavior

No error because module defaults to esnext.

Additional information about the issue

In Announcing TypeScript 6.0, it says module defaults to esnext: Similarly, the new default module is esnext, acknowledging that ESM is now the dominant module format.

But in TSConfig Reference, it's CommonJS if target is ES5; ES6/ES2015 otherwise.

In the code, I don't think the default value is esnext. Otherwise, we wouldn't be getting the TS2823 error.

Activity

  1. mkantor commented on Apr 1, 2026

    @mkantor
    Contributor

    I suspect that module is actually currently defaulting to es2022.

    Since #63067, target defaults to ScriptTarget.LatestStandard, which is currently es2025, and that means the computed default for module is es2022.

    Also, I get the same error message with npx tsc --module es2022 index.ts.

  2. mkantor commented on Apr 1, 2026

    @mkantor
    Contributor

    This also made me notice that the documentation for the default value of target is currently wrong (at least the "ES5 otherwise" bit). This section also still mentions ES3 as an allowed target value, but that's no longer true.

  3. mkantor commented on Apr 1, 2026

    @mkantor
    Contributor

    Re-reading that list item in the announcement post, I wonder if it's just a typo/editing mistake. Setting aside the incorrect information, the prose weirdly repeats itself ("module defaults to esnext: Similarly, the new default module is esnext"). I can't figure out what it's supposed to be saying, though.

  4. mkantor commented on Apr 14, 2026

    @mkantor
    Contributor

    This isn't directly related to the specific thing called out by this issue, but I noticed another minor problem in the announcement post. The "Deprecated: outFile" section says "The --outFile option has been removed from TypeScript 6.0", but that's not true (it's merely been deprecated). Maybe this sentence was supposed to say "7.0" instead of "6.0".

  5. matthewbordas commented on May 19, 2026

    @matthewbordas

    Sébastien Règne (@regseb) Matt Kantor (@mkantor) I'm also seeing interesting behavior most likely related to this and put some notes together here.

    The docs are getting harder to follow with this last release. The updates to compiler setting defaults don't appear to have been synced with the other core pages (as mentioned above around the module field)?

  6. mkantor commented on May 19, 2026

    @mkantor
    Contributor

    Yeah, https://typescriptlang.org/tsconfig is in need of updates (perhaps other documentation pages too). See #63392.

  7. jonkoops commented on Jul 9, 2026

    @jonkoops

    I've opened a PR to fix this on the documentation website: microsoft/TypeScript-Website#3608

    It updates the documented default for module in tsconfigRules.ts to reflect the current computation logic (derived from target, not the old ES5/ES2015 split).

  8. added a commit that references this issue on Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

DocsThe issue relates to how you learn TypeScript

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions