GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Importing JSON file as type only conflicts with import attribute type requirement · Issue #60724 · microsoft/TypeScript

Importing JSON file as type only conflicts with import attribute type requirement #60724

New issue
Copy link
New issue
Copy link
Closed
#60749
Closed
Importing JSON file as type only conflicts with import attribute type requirement#60724
#60749
Copy link
Assignees
andrewbranch
Labels
BugA bug in TypeScriptFix AvailableA PR has been opened for this issue
Milestone
TypeScript 5.7.3

Description

@Le0Michine
Lev (Le0Michine)
opened on Dec 9, 2024
Issue body actions

🔎 Search Terms

"import attributes", "import assert", "type json"

🕗 Version & Regression Information

  • This changed between versions 5.3.3 and 5.7.2
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about import attributes and type only imports
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Couldn't get playground to create a separate module, so attaching a minimal example
typescript-json-repro.zip

run

npm i
npm run build

💻 Code

// tsc fails with: Importing a JSON file into an ECMAScript module requires a 'type: "json"'
import type enMessages from "./en.json";

🙁 Actual behavior

When I try to address the issue as TSC suggests I run into another:

// tsc fails with: Importing a JSON file into an ECMAScript module requires a 'type: "json"'
import type enMessages from "./en.json";

// tsc fails with: Import attributes cannot be used with type-only imports or exports. ts(2857)
import type enMessages from "./en.json" with { type: "json" };

// tsc is happy but me and eslint are not, I don't use imported module for anything other than typings in this case
import enMessages from "./en.json" with { type: "json" };

🙂 Expected behavior

Type only imports should not require specifying 'type: "json"' as they are not retained in the JS output. Alternatively import attributes should be allowed with type only imports. One of the options below should work

import type enMessages from "./en.json";
import enMessages from "./en.json" with { type: "json" };

Additional information about the issue

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "esModuleInterop": true,
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "resolveJsonModule": true,
    "declaration": true,
    "rootDir": "src",
    "outDir": "dist/types"
  },
  "include": ["./src/**/*", "./src/**/*.json"],
  "exclude": ["build", "node_modules", "dist"]
}
Reacted by Alfonsus Ardani

Activity

  1. thewilkybarkid commented on Dec 11, 2024

    @thewilkybarkid
    Chris Wilkinson (thewilkybarkid)
    on Dec 11, 2024
    More actions

    I think the second option in expected behaviour should be:

    import type enMessages from "./en.json" with { type: "json" };

    (i.e. with a type)

  2. thewilkybarkid commented on Dec 11, 2024

    @thewilkybarkid
    Chris Wilkinson (thewilkybarkid)
    on Dec 11, 2024
    More actions

    We've encountered the same issue when upgrading from 5.6.3 to 5.7.2 (PREreview/prereview.org#2130). Making it a regular import leads to an import/no-extraneous-dependencies ESLint failure, as the package we're importing from is only used for its types (as so is a dev dependency).

  3. Ryan Cavanaugh (RyanCavanaugh)
    added
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Dec 12, 2024
  4. Ryan Cavanaugh (RyanCavanaugh)
    assigned
    Andrew Branch (andrewbranch)
    on Dec 12, 2024
  5. Andrew Branch (andrewbranch)
    added
    BugA bug in TypeScript
    and removed
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Dec 12, 2024
  6. Andrew Branch (andrewbranch)
    added this to the TypeScript 5.7.3 milestone on Dec 12, 2024
  7. TypeScript Bot (typescript-bot)
    added
    Fix AvailableA PR has been opened for this issue
    on Dec 12, 2024
  8. Andrew Branch (andrewbranch)
    closed this as completedin #60749on Dec 12, 2024
  9. microsoft
    locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @andrewbranch
    Andrew Branch (andrewbranch)

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Milestone

    • TypeScript 5.7.3

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.