I have a simple file that imports a json:
main.ts
import json from './file.json'
However, deno throws the following error when importing a json file:
$ deno run main.ts
Compile file:///home/path/to/project/main.ts
error: Uncaught TypeError: Cannot resolve extension for "file:///home/path/file.json" with mediaType "Json".
at getExtension ($deno$/compiler.ts:218:13)
at new SourceFile ($deno$/compiler.ts:263:22)
at Function.addToCache ($deno$/compiler.ts:339:16)
at processImports ($deno$/compiler.ts:743:31)
at async processImports ($deno$/compiler.ts:753:7)
at async compile ($deno$/compiler.ts:1316:31)
at async tsCompilerOnMessage ($deno$/compiler.ts:1548:22)
at async workerMessageRecvCallback ($deno$/runtime_worker.ts:74:9)
The file path is correct and the file is a valid JSON. The Typescript compiler should allow this by default.
I also tried to explicitly enable resolveJsonModule
:
tsconfig.json
{
"compilerOptions": {
"resolveJsonModule": true
},
"include": [
"**/*"
]
}
and run it with the config but still get the same error:
$ deno run main.ts --config=tsconfig.json
Compile file:///home/path/to/project/main.ts
error: Uncaught TypeError: Cannot resolve extension for "file:///home/path/file.json" with mediaType "Json".
at getExtension ($deno$/compiler.ts:218:13)
at new SourceFile ($deno$/compiler.ts:263:22)
at Function.addToCache ($deno$/compiler.ts:339:16)
at processImports ($deno$/compiler.ts:743:31)
at async processImports ($deno$/compiler.ts:753:7)
at async compile ($deno$/compiler.ts:1316:31)
at async tsCompilerOnMessage ($deno$/compiler.ts:1548:22)
at async workerMessageRecvCallback ($deno$/runtime_worker.ts:74:9)
What's wrong here?