Closed
Description
🔎 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
and5.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
// 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.