-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: ENOENT: no such file or directory, open '/home/amura/generateSlipKylas/.next/server/app/api/generatepdf/data/Helvetica.afm' #1467
Comments
I tried making a file name data and then added Helvetica.afm font file in it , but doesn't work |
I'm having the same issue but my error for the missing file was from a different directory. To confirm I'm using next 13.5.4 and an api route in the app dir /src/app/api/pdf/route.js
At the top of my pdf api route I added the following to check if the font files exist and if not copy them to where it was moaning about not finding them and it's working for me.
|
calling from pages folder worked for me |
Yes calling from pages worked for me too , but i needed it on server side . |
Use API folder inside pages router |
I noticed you're using ESM import statements. So this is probably the same problem as in my case: #1491 |
I am using nextjs server actions to generate pdf document and I have a similar error Action error: ENOENT: no such file or directory, open '/......../.next/server/vendor-chunks/data/Helvetica.afm' |
Hi, I am facing the same issue here, for local testing, I have added that font to my local system, but when I deployed it to server it didn't work, Is there any working solution. |
Running into this issue as well, fixed it by editing the following copy action to webpack configuration in Not ideal since the path of the route is hardcoded here. const destination = isDev ? `.next/server/vendor-chunks/data/[name][ext]` : `.next/server/<<add your path to route handler here>>/data/[name][ext]`;
config.plugins.push(
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(process.cwd(), 'node_modules/pdfkit/js/data/*.afm'),
to: path.resolve(process.cwd(), destination),
},
],
})
); Update new PDFDocument({
font: 'path/to/font.ttf',
}) Then the default Helvetica.afm is not loaded. |
It's sad that this error happens and it isn't been solved. As a workaround I did the suggestion provided above, here is the code that I've used: |
For the people using Next.JS app router, the real way to solve it, is by adding this property to you next config with Contrary to what the property name implies, it also applies to route handlers. experimental: {
serverComponentsExternalPackages: ['pdfkit']
} |
Description of the problem
I am having a issue when i am trying to create a pdf in api folder of nextjs 13 .
Code sample
import fs from 'fs';
import path, { join } from 'path';
import { NextRequest, NextResponse } from "next/server";
export async function POST(request) {
const res = await request.json()
console.log(res)
const PDFDocument = require('pdfkit');
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));
doc
.save()
.moveTo(100, 150)
.lineTo(100, 250)
.lineTo(200, 250)
.fill('#FF3300');
doc.end();
// Register fontkit with PDFDocument
try {
} catch (error) {
console.log("error", error)
let error_response = {
status: "error",
message: error.message,
};
return new NextResponse(JSON.stringify(error_response), {
status: 500,
headers: { "Content-Type": "application/json" },
});
}
}
ERROR:
Error: ENOENT: no such file or directory, open '/home/amura/generateSlipKylas/.next/server/app/api/generatepdf/data/Helvetica.afm'
at Object.openSync (node:fs:601:3)
at Object.readFileSync (node:fs:469:35)
at Object.Helvetica (webpack-internal:///(rsc)/./node_modules/pdfkit/js/pdfkit.js:5021:19)
at new StandardFont (webpack-internal:///(rsc)/./node_modules/pdfkit/js/pdfkit.js:5057:58)
at PDFFontFactory.open (webpack-internal:///(rsc)/./node_modules/pdfkit/js/pdfkit.js:5349:24)
at PDFDocument.font (webpack-internal:///(rsc)/./node_modules/pdfkit/js/pdfkit.js:5401:37)
at PDFDocument.initFonts (webpack-internal:///(rsc)/./node_modules/pdfkit/js/pdfkit.js:5375:18)
at new PDFDocument (webpack-internal:///(rsc)/./node_modules/pdfkit/js/pdfkit.js:7616:14)
at POST (webpack-internal:///(rsc)/./src/app/api/generatepdf/route.js:19:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async eval (webpack-internal:///(rsc)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:253:37) {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/home/amura/generateSlipKylas/.next/server/app/api/generatepdf/data/Helvetica.afm'
}
Your environment
The text was updated successfully, but these errors were encountered: