Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewriteRelativeImportExtensions and resolveJsonModule #60392

Closed
jamiebuilds opened this issue Nov 1, 2024 · 0 comments · Fixed by #60415
Closed

rewriteRelativeImportExtensions and resolveJsonModule #60392

jamiebuilds opened this issue Nov 1, 2024 · 0 comments · Fixed by #60415
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@jamiebuilds
Copy link

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

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Nov 1, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.7.1 milestone Nov 1, 2024
@andrewbranch andrewbranch added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Nov 4, 2024
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
4 participants