繁体   English   中英

html-minifier node.js TypeError:value.replace不是函数

[英]html-minifier node.js TypeError: value.replace is not a function

我正在尝试使用节点模块html-minifier缩小html文件。 为此,我创建了这个小的node.js文件,它应该能够执行此操作

'use strict'

var fs = require('fs');
var minifier = require('html-minifier').minify;

var htmlFile = fs.readFileSync("users/email/test.html");
var output = minifier(htmlFile, {
    removeAttributeQuotes: true
});

process.stdout.write(output);

但是当我运行程序时,出现以下错误。

TypeError: value.replace is not a function

知道为什么会这样。 我正在使用html-minifier的4.0.0版本

由于您尚未指定文本编码,因此readFileSync返回Buffer ,而不是字符串。 请参阅readFileSync文档

如果知道要使用的编码,则可以将其指定为第二个参数:

var htmlFile = fs.readFileSync("users/email/test.html", "utf8");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM