erztemplerobba
erztemplerobba
Explore posts from servers
RRailway
Created by erztemplerobba on 6/3/2023 in #✋|help
ENOENT Error with puppeteer when creating .pdf
I am using puppeteer in my express server app to create a .pdf file from a html template. It works fine locally and throws this error when I upload the server app to railway. (from railway deploy log):
tempPath /app/create-invoice/temp/invoice_pi_3NERfyItN31KXN7T2Os3CniD.pdf
[Error: ENOENT: no such file or directory, open '/app/create-invoice/temp/invoice_pi_3NERfyItN31KXN7T2Os3CniD.pdf'] {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/app/create-invoice/temp/invoice_pi_3NERfyItN31KXN7T2Os3CniD.pdf'
}
tempPath /app/create-invoice/temp/invoice_pi_3NERfyItN31KXN7T2Os3CniD.pdf
[Error: ENOENT: no such file or directory, open '/app/create-invoice/temp/invoice_pi_3NERfyItN31KXN7T2Os3CniD.pdf'] {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/app/create-invoice/temp/invoice_pi_3NERfyItN31KXN7T2Os3CniD.pdf'
}
This is the code that I'm using in my node express server:
getTemplateHtml().then(async (res) => {
const template = hb.compile(res, { strict: true });
const result = template(data);
const html = result;
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
const page = await browser.newPage()
// set the page content as the generated html by handlebars
await page.setContent(html)
// use pdf function to generate the pdf
const tempPath = path.join(__dirname, '.', 'temp', 'invoice_' + data.payment_intent + '.pdf')
console.log('tempPath', tempPath)
await page.pdf({ path: tempPath, format: 'A4' })
await browser.close();
return true
}).catch(err => {
console.error(err)
});
}
getTemplateHtml().then(async (res) => {
const template = hb.compile(res, { strict: true });
const result = template(data);
const html = result;
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
const page = await browser.newPage()
// set the page content as the generated html by handlebars
await page.setContent(html)
// use pdf function to generate the pdf
const tempPath = path.join(__dirname, '.', 'temp', 'invoice_' + data.payment_intent + '.pdf')
console.log('tempPath', tempPath)
await page.pdf({ path: tempPath, format: 'A4' })
await browser.close();
return true
}).catch(err => {
console.error(err)
});
}
The console.log('tempPath', tempPath) is the first line in the error message. The next line (pdf creation) seems to create the error.:
await page.pdf({ path: tempPath, format: 'A4' })
await page.pdf({ path: tempPath, format: 'A4' })
Help would be much appreciated.
10 replies
RRailway
Created by erztemplerobba on 8/30/2022 in #✋|help
Strapi database reset after re-deploy
I'm curious if it's working as intended that the Postgres database deletes all custom data and resets to default whenever I deploy my newest Strapi backend from git. If so, is there a workaround to have the database persist?
35 replies