【发布时间】:2021-03-07 09:14:27
【问题描述】:
我希望能够在 NestJS 应用程序中将 .html 文件作为字符串模板导入。 为了满足 TypeScript,我像这样创建了 text.d.ts:
declare module "*!text" {
const content: string;
export default content;
}
并将其导入到这样的文件中:
import html from 'src/templates/test!text';
TypeScript 没有任何抱怨。但是,当我尝试运行 应用程序我收到以下错误:
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'src/templates/test!text'
如何解决这个错误?
提前致谢。
【问题讨论】:
-
您是否尝试使用相对路径而不是这个绝对路径
'src/templates/test!text'? -
@MicaelLevi 在导入中路径是相对的。
标签: nestjs