我想导入一个文本文件:
import text from "./text.txt";我有一个文件,里面有:
declare module "*.txt" {
const content: string;
export default content;
}但是,ts-node会抱怨:
error TS2307: Cannot find module './text.txt' or its corresponding type declarations.请注意,我不能使用fs模块来读取文件,因为我也在web前端使用相同的代码(其中导入由绑定器解决)。
编辑
尝试使用第一个答案中的建议:
import text from "./text.txt!text";使用
declare module "*!text" {
const content: string;
export default content;
}我得到了这个错误:
Cannot find module './text.txt!text' from '...'发布于 2021-08-22 10:30:47
你必须告诉typescript你的模块将是这样的字符串类型: import text from "./text.txt!text";
https://stackoverflow.com/questions/68880386
复制相似问题