我有一个导入 json 的简单文件:
主要的.ts
import json from './file.json'
但是,在导入 json 文件时,deno 会抛出以下错误:
$ 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)
文件路径正确且文件是有效的 JSON。默认情况下,Typescript 编译器应该允许这样做。
我还尝试明确启用resolveJsonModule
:
tsconfig.json
{
"compilerOptions": {
"resolveJsonModule": true
},
"include": [
"**/*"
]
}
并使用配置运行它,但仍然得到相同的错误:
$ 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)
这里有什么问题?