sidebase/nuxt-pdf

useRuntimeConfig missing when generating PDF serverside

digitalkaoz opened this issue · 4 comments

Environment

------------------------------
- Operating System: Darwin
- Node Version:     v21.2.0
- Nuxt Version:     3.10.3
- CLI Version:      3.10.1
- Nitro Version:    -
- Package Manager:  pnpm@8.13.1
- Builder:          -
- User Config:      devtools, modules, formkit, colorMode, kinde, stripe, routeRules
- Runtime Modules:  @formkit/nuxt@1.5.9, @nuxtjs/tailwindcss@6.11.4, @unlok-co/nuxt-stripe@2.0.0, @nuxtjs/color-mode@3.3.2, @sidebase/nuxt-pdf@1.0.0-alpha.0
- Build Modules:    -
------------------------------

Reproduction

see below

Describe the bug

when trying to generate a pdf serverside, i get this error (logs section):

the api endpoint looks like this:

import { createPDF, streamReturnPDF } from '#pdf'

export default defineEventHandler(async (event) => {
  const pdf = createPDF()
  pdf.text('Welcome to NuxtPDF!')
  pdf.end()
  return streamReturnPDF(event, pdf)
}

Additional context

No response

Logs

[nuxt] [request error] [unhandled] [500] useRuntimeConfig is not defined
  at createPDF (./node_modules/.pnpm/@sidebase+nuxt-pdf@1.0.0-alpha.0_nuxt@3.10.3_vite@5.1.5/node_modules/@sidebase/nuxt-pdf/dist/runtime/server/pdf.mjs:5:36)  
  at Object.handler (./server/api/generator.ts:50:1)  
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)  
  at async Object.handler (./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:1962:19)  
  at async Server.toNodeHandle (./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2249:7)

what is happening witbh thtis, this libary does not work on server side atm?

it doesnt work here...the PR fixes it

Hi @digitalkaoz @moshetanzer 👋

I had recently begun rewriting parts of the module to provide a Nuxt wrapper for PDFKit along with some helpers. The current 1.0.0 alpha releases are not to be used in production yet!

I am still unsure about the future of this approach, or if we will find a better way to generate PDFs inside Nuxt. In #25 I had outlined some next steps for this module, but am still unsure about how much value they will actually bring.

Most of the current server side functionality could be easily added yourself in a project by installing PDFKit and then writing some helper functions. I am still thinking of ways to provide more value, before continuing to push the next release!