Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

rewriteRelativeImportExtensions and resolveJsonModule #60392

Copy link
Copy link
@jamiebuilds

Description

@jamiebuilds
Issue body actions

🔎 Search Terms

  • rewriteRelativeImportExtensions
  • resolveJsonModule
  • ts(2876)
  • rewrite json module
  • import json path
  • tsconfig, config options
  • file path name
  • import assert type json

🕗 Version & Regression Information

  • This changed between versions N/A and 5.7.0-beta
  • This changed in commit or PR Rewrite relative import extensions with flag #59767
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about these config flags and JSON more generally (nothing found)
  • I was unable to test this on prior versions because rewriteRelativeImportExtensions did not exist

⏯ Playground Link

No response

💻 Code

// package.json
{
  "type": "module"
}
// tsconfig.json
{
  "compilerOptions": {
    "module": "NodeNext",
    "rewriteRelativeImportExtensions": true,
    "resolveJsonModule": true,
  }
}
// example.json
{ "example": true }
// example.ts
import * as example from "./example.json" assert { type: "json" }
                         ^^^^^^^^^^^^^^^^
// This relative import path is unsafe to rewrite because it looks
// like a file name, but actually resolves to "./example.json". ts(2876)

🙁 Actual behavior

import * as example from "./example.json" assert { type: "json" }
                         ^^^^^^^^^^^^^^^^
// This relative import path is unsafe to rewrite because it looks
// like a file name, but actually resolves to "./example.json". ts(2876)

🙂 Expected behavior

No error

Additional information about the issue

The documentation says:

/* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */

I wouldn't expect this to apply any sort of change to a .json file.

hartimcwildfly and andrewbranch

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.