Split e-invoice exports into a separate server-only subpath

@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 <PDFViewer>, the plain PDF renderers).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Marco
2026-07-23 11:31:15 +00:00
parent 63e3a02212
commit 68d7054557
3 changed files with 33 additions and 2 deletions
+10
View File
@@ -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",
+12
View File
@@ -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";
+11 -2
View File
@@ -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).