错误:写入 EPIPE
Error: write EPIPE
我不断收到以下错误:
Error: write EPIPE
at errnoException (net.js:901:11)
at Object.afterWrite (net.js:718:19)
当我运行以下函数时:
router.route('/certificationService')
.post(function (req, res) {
var html = null,
certificate = req.body.certificate,
lang = req.body.lang,
now = new Date(),
dd = now.getDate(),
mm = now.getMonth() + 1,
yyyy = now.getFullYear();
if (dd < 10) dd = '0' + dd;
if (mm < 10) mm = '0' + mm;
switch (lang) {
case 'da':
var text = {
title: 'Certifikat',
first_line: 'Dette certifikat er givet til',
second_line: 'for gennemførelsen af certificeringen',
score: 'Score',
date: 'D.',
organization: 'Organisation'
};
break;
case 'en':
var text = {
title: 'Certificate',
first_line: 'This certificate was given to',
second_line: 'for the completion of certification',
score: 'Score',
date: 'The',
organization: 'Organization'
};
break;
case 'no':
var text = {
title: 'Sertifikat',
first_line: 'Dette sertifikatet er gitt til',
second_line: 'gjennomføring av sertifisering',
score: 'Score',
date: 'D.',
organization: 'Organisation'
};
break;
case 'de':
var text = {
title: 'Zertifikat',
first_line: 'Dieses zertifikat wird eine für gegebene',
second_line: 'die Umsetzung der zertifizierung',
score: 'Ergebnis',
date: 'D.',
organization: 'Unternehmen'
};
break;
default:
}
var data = {
firstname: certificate.user.profile.firstname,
lastname: certificate.user.profile.lastname,
organization: certificate.user.organization.name,
module_name: certificate.name,
medal: env + certificate.medal.image_path,
score: certificate.score,
date: dd + '-' + mm + '-' + yyyy,
show_score: certificate.show_score,
description: certificate.text,
company_logo: env + req.body.organization.logo_file_name,
company_name: req.body.organization.name,
text: text
};
// rendering the ejs file
ejs.renderFile('./templates/certificate.ejs', {data: data}, function (err, result) {
if (result) {
html = result;
} else {
res.end('An error occurred: ' + err);
console.log(err);
}
});
var options = {
filename: './user_resources/certificate/' + certificate.user.id + '/' + certificate.name.replace(/ +?/g, '_') + '.pdf',
format: 'A4',
orientation: 'portrait',
type: "pdf",
timeout: 30000
};
pdf.create(html, options).toFile(function (err, res) {
if (err) return console.log("This is where it goes wrong"+ err);
console.log(res);
});
var file = {
originalname: certificate.name.replace(/ +?/g, '_') + '.pdf',
path: './user_resources/certificate/' + certificate.user.id + '/'
};
var media = new Media(file, './user_resources/certificate/' + certificate.user.id + '/');
var token = jwt.encode({
mediaObject: media
}, require('../secret')());
res.status(200).json(token);
});
所以我试图环顾四周寻找解决方案,有人说:
确保在您的计算机上同时安装了 imagemagick 和 graphicsmagick。
所以我使用以下方法安装了它:
$ sudo add-apt-repository ppa:dhor/myway
$ sudo apt-get update
$ sudo apt-get install graphicsmagick
然而没有任何运气。
以下是我的module
的依赖项:
var fs = require('fs'),
jwt = require('jwt-simple'),
pdf = require('html-pdf'),
path = require('path'),
ejs = require('ejs'),
async = require('async'),
DataTypes = require("sequelize"),
PDFKit = require('pdfkitjs'),
gm = require('gm').subClass({imageMagick: true}),
ffmpeg = require('fluent-ffmpeg'),
sys = require('util'),
exec = require('child_process').exec,
我真的希望你们中的一些人能够帮助我!
在某些操作系统中,您会收到此错误。要为任何操作系统修复此问题,只需指定 phantomjs:
var phantomjs = require('phantomjs');
var options = {
phantomPath: phantomjs.path,
filename: './user_resources/certificate/' + certificate.user.id + '/' + certificate.name.replace(/ +?/g, '_') + '.pdf',
format: 'A4',
orientation: 'portrait',
type: "pdf",
timeout: 30000
};
我今天在 aws Lambda 上遇到了这个问题,并在搜索时降落在这里。我也发现并成功解决了这个问题,所以我认为我应该通过在这里回答这个问题来为社区做出贡献。
首先,我们需要一些项目来快速测试lambda,这是一个。
易于部署的 html-pdf for AWS Lambda 实施
但是任何幻影代码都会在此链接上抛出Error: write EPIPE
下一个 naeemshaikh27 已经发布了所有必需的依赖项,我认为这些依赖项应该在某处列出,但除了这个之外。配置也解释清楚
Aws Lambda PhontomJS dependencies for Amazon Linux 2
选项对象中添加 phantomjs 的路径
var options = {
phantomPath: __dirname + "/pathToNodeModules/phantomjs/bin/phantomjs",
filename: './user_resources/certificate/' + certificate.user.id + '/' + certificate.name.replace(/ +?/g, '_') + '.pdf',
format: 'A4',
orientation: 'portrait',
type: "pdf",
timeout: 30000
};
这样做 如果您在 docker alpine 映像中运行该应用程序,因为 phantomjs 预构建在 alpine 上不起作用
如果以前的解决方案都不起作用,请尝试更新您的"选项"
var options = {
childProcessOptions: {
env: {
OPENSSL_CONF: "/dev/null",
},
},
filename: './user_resources/certificate/' + certificate.user.id + '/' + certificate.name.replace(/ +?/g, '_') + '.pdf',
format: 'A4',
orientation: 'portrait',
type: "pdf",
timeout: 30000};
这对我来说是有用的。
使用的是 linux,@Vishvendra Singh 的回答可能会正常工作。但是,如果您使用的是Windows,则需要执行一个额外的步骤。即使用 Amazon Linux2 在 ec2 实例上编译二进制文件(使用命令 chmod 777 * 或 chmod 777 binary_file_name 使它们可执行),仅将它们压缩到那里。然后部署它。然后它会正常工作。
- 在.csv文件中写入学位符号
- 在node.js中写入ECONNRESET错误和套接字连接检查
- 在页面卸载时写入HTML5 FileSystem API存储
- 根据HTML文件名授予web服务器写入权限
- 如何让Meteor应用程序使用python脚本写入数据库
- 如何同步写入process.stdout
- 函数式javascript读取、异步、写入结果
- html5画布在同一行中写入多个字体
- firebase中有没有一种方法可以防止快速连续写入
- 通过查询替换/写入文件中的代码
- Uploadify:写入完成,但没有文件上传
- 使用javascript读取和写入json文件
- 使用Office.js在Excel中将20000多个单元格写入表失败
- 如何将javascript变量写入sql数据库
- 一个javascript实现base64图像编码并将结果写入文本文件
- JQuery:如果attr(左)等于0px,如何写入
- 使用对数据库的写入权限保护文件
- 节点.js - 事件.js:154 抛出错误写入 EPIPE;程序崩溃
- 错误:写入 EPIPE
- "错误:写入EPIPE“;在node.js上使用Socket.io