在带有 checkJs
的 VsCode 中打开的 nodej 项目中启用,当需要一个 json 文件时
const myFile = require('./my-file.json')
这会产生错误
[ts] Cannot find module
.如何删除错误警告?
我尝试过了:
"resolveJsonModule": true
到compilerOptions
在 jsconfig.json
,但它不起作用。 typing.d.ts
包含以下内容的文件:declare module '*.json' {
const value: any;
export default value;
}
但是现在,有一个错误[ts] Type 'typeof import("*.json")' must have a '[Symbol.iterator]()' method that returns an iterator. [2488]
最佳答案
你应该添加"resolveJsonModule":true
作为 的一部分编译器选项 到 tsconfig.json。
关于javascript - 需要一个 json 文件导致错误 : Cannot find module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53320187/