From 68d705455726eaa24f1b4b3183b99af3061e1ea8 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 23 Jul 2026 11:31:15 +0000 Subject: [PATCH] Split e-invoice exports into a separate server-only subpath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @e-invoice-eu/core pulls in Node-only dependencies (tmp/tmp-promise, for a LibreOffice conversion path this package never actually takes) that broke Next.js's client bundle the moment renderInvoiceEInvoice() was re-exported from the main "." entry — that entry is reachable from a Client Component (email-templates.ts's Live Preview import chain), so the bundler tried pulling e-invoice-eu/core in client-side too. New "@einfach-produktiv/invoicing/einvoice" subpath (package.json "exports" map + src/einvoice/index.ts) holds only the e-invoice generation functions — server-only code (API routes, Server Components, Payload job handlers) imports from there instead. The main "." entry keeps everything already browser-safe (computeTaxBreakdown, formatters, InvoiceDocument for Live Preview's , the plain PDF renderers). Co-Authored-By: Claude Sonnet 5 --- package.json | 10 ++++++++++ src/einvoice/index.ts | 12 ++++++++++++ src/index.ts | 13 +++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/einvoice/index.ts diff --git a/package.json b/package.json index 02e665d..d26ee78 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,16 @@ "type": "module", "main": "./src/index.ts", "types": "./src/index.ts", + "exports": { + ".": { + "types": "./src/index.ts", + "default": "./src/index.ts" + }, + "./einvoice": { + "types": "./src/einvoice/index.ts", + "default": "./src/einvoice/index.ts" + } + }, "scripts": { "typecheck": "tsc --noEmit", "test": "vitest run", diff --git a/src/einvoice/index.ts b/src/einvoice/index.ts new file mode 100644 index 0000000..210b3bd --- /dev/null +++ b/src/einvoice/index.ts @@ -0,0 +1,12 @@ +// Server-only entry point (`@einfach-produktiv/invoicing/einvoice`), +// separate from the package's main "." entry — see that entry's own +// comment on why: @e-invoice-eu/core pulls in Node-only dependencies that +// break a client bundle the moment they're reachable from code a Client +// Component also imports. Only import this from server-only code (API +// routes, Server Components, Payload job handlers) — never from anything +// a "use client" file also imports, directly or transitively. +export { renderInvoiceEInvoice, renderCorrectionInvoiceEInvoice } from "./renderEInvoice"; +export { buildEInvoiceData, buildCorrectionEInvoiceData } from "./buildEInvoiceData"; +export type { InvoiceOrder } from "../invoicePdf"; +export type { CorrectionInvoiceKind, CorrectionInvoiceOrder } from "../correctionInvoicePdf"; +export type { InvoiceSeller } from "../seller"; diff --git a/src/index.ts b/src/index.ts index cb59c10..92b1dd7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,5 +14,14 @@ export { type CorrectionInvoiceItem, type CorrectionInvoiceOrder, } from "./correctionInvoicePdf"; -export { renderInvoiceEInvoice, renderCorrectionInvoiceEInvoice } from "./einvoice/renderEInvoice"; -export { buildEInvoiceData, buildCorrectionEInvoiceData } from "./einvoice/buildEInvoiceData"; + +// E-invoice generation (renderInvoiceEInvoice/renderCorrectionInvoiceEInvoice) +// is deliberately NOT re-exported from here — @e-invoice-eu/core pulls in +// Node-only dependencies (tmp/tmp-promise, used for its LibreOffice +// conversion path, even though this package never takes that path) that +// broke Next.js's client bundle the moment they got pulled in transitively +// through this same barrel file (this file is itself imported by +// email-templates.ts, which a Client Component needs for its Live +// Preview). Import from "@einfach-produktiv/invoicing/einvoice" instead — +// a separate subpath, server-only code paths only (see that folder's own +// index.ts).