Skip to content

rewriteRelativeImportExtensions and resolveJsonModule #60392

Closed
@jamiebuilds

Description

@jamiebuilds

🔎 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.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions