simonhaenisch / md-to-pdf

Hackable CLI tool for converting Markdown files to PDF using Node.js and headless Chrome.
https://www.npmjs.com/md-to-pdf
MIT License
1.12k stars 108 forks source link

Can not find highlight style #279

Closed duhoang00 closed 7 months ago

duhoang00 commented 7 months ago

I'm using nextjs 14, this code part is in "use server" file

This is the code

"use server";

export async function convertToPdf(content: string) {
  const pdf = await mdToPdf(
    { content: "# Hello, World" },
    {
      dest: "./public/files/report.pdf",
      stylesheet: [process.cwd() + "/node_modules/md-to-pdf/markdown.css"],
    }
  ).catch(console.error);
}

And I'm getting this error, I'm pretty sure that there is the github.css file in node_modules/highlight.js but maybe the (action-browser) prevent it to be found. Can someone help me here? Thank you.

[Error: ENOENT: no such file or directory, open '/project_name/(action-browser)/node_modules/highlight.js/styles/github.css'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/project_name/(action-browser)/node_modules/highlight.js/styles/github.css'
}
duhoang00 commented 7 months ago

Since this is relevant to nextjs 14, I'm gonna close this. If anyone also has this issue, try to add this to your next.config.js

experimental: {
    serverComponentsExternalPackages: ["md-to-pdf"],
  },