【发布时间】:2021-05-18 16:59:40
【问题描述】:
我尝试使用 readFileSync 方法获取文件:
import fs from 'fs';
import path from 'path';
const templateFile = fs.readFileSync(
path.resolve(
__dirname,
'../mail/templates/exampleTemplate.html',
),
'utf-8',
);
Nest 仍然返回错误:
TypeError:无法读取未定义的属性“readFileSync”
我尝试过使用路径:./templates/exampleTemplate.html,但结果是一样的
我有一个结构文件:
【问题讨论】:
-
您如何需要
fs模块?可以分享require语句的代码吗? -
import fs from 'fs'; -
@ArunKumarMohan 您的查询很有帮助,我将
import更改为require,现在文件可以正常工作了。谢谢;) -
不客气。您可以使用
import,但它必须使用不同的语法。我已经在回答中解释过了。