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
Problem building project in NodeJS #474
Comments
Hi @mitcheljimenez ! Can you give me the full code of what you are trying? I guess |
Oh hi! Sorry for the late reply. I downgraded to version 2.0.2 and it works now. I tried the solution you referenced but after upgrading it again to 4.0.0 but the same error appears, I even tried not importing Template type and just cast the JSON file imported as any so typescript linter don't complain. This is the complete file (I did not remove my code so sorry for the import { Quotation } from '@common/entities/quotation.entity';
import summaryPdfTemplate from './summary-pdf.template.json';
import { generate } from '@pdfme/generator';
import type { Template } from '@pdfme/common';
import { formatDocumentNumber } from '@common/helpers/format-document-number';
import { DateTime } from 'luxon';
import { getProposalsByProductName } from './helpers/get-proposals-by-product-name';
const mapPaymentManagementNumberToName = (
paymentManagement: Quotation['conditions']['paymentManagement']
): string => { ... };
const getProposalConditionsText = (
proposal: Quotation['proposals'][number]
): string => { ... }
export const createSummaryPdf = async ({
quotation,
ufRate,
}: {
quotation: Omit<Quotation, 'id'>;
ufRate: number;
}): Promise<Buffer> => {
const solucionMovilEstandarProposals = getProposalsByProductName({
proposals: quotation.proposals,
productName: 'SOLUCION MOVIL ESTANDAR',
});
const solucionMovilDosProposals = getProposalsByProductName({
proposals: quotation.proposals,
productName: 'SOLUCION MOVIL 2.0',
});
const solucionMovilMasDosProposals = getProposalsByProductName({
proposals: quotation.proposals,
productName: 'SOLUCION MOVIL MAS 2.0',
});
const inputs = [
{
executiveName: quotation.executiveName,
policyholderName: `${quotation.policyholder.name} ${quotation.policyholder.firstLastName} ${quotation.policyholder.secondLastName}`,
policyholderDocumentNumber: formatDocumentNumber(
quotation.policyholder.documentNumber
),
policyholderEmail: quotation.policyholder.email ?? '',
policyholderPhoneNumber: quotation.policyholder.mobileNumber ?? '',
vehicleType: '',
vehicleBrandName: quotation.vehicle.brandName,
vehicleModelName: quotation.vehicle.modelName,
vehicleYear: quotation.vehicle.year.toString(),
vehicleUse: quotation.vehicle.useType,
vehicleState: quotation.vehicle.state,
vehicleSpecificUse: quotation.vehicle.useType,
proposalsTableTitle: `OPCIONES DE PRODUCTOS ${mapPaymentManagementNumberToName(
quotation.conditions.paymentManagement
)} ${quotation.conditions.paymentFeesCount ?? 0} CUOTAS`,
quotationId: quotation.externalQuotationId,
quotationExtraData: `Valor referencial a la UF del día: $ ${ufRate.toLocaleString(
'es-CL'
)} - Fecha de Cotización: ${DateTime.fromJSDate(quotation.createdAt, {
zone: 'America/Santiago',
}).toFormat('dd-MM-yyyy HH:mm:ss')} - Vigencia de Cotización: ${Math.ceil(
DateTime.fromJSDate(quotation.expiresAt).diff(
DateTime.fromJSDate(quotation.createdAt),
'days'
).days
)} Días`,
noDeductibleSM2Data: getProposalConditionsText(
solucionMovilDosProposals['Sin Deducible']
),
'3UFDeductibleSM2Data': getProposalConditionsText(
solucionMovilDosProposals['Deducible 3 UF']
),
'5UFDeductibleSM2Data': getProposalConditionsText(
solucionMovilDosProposals['Deducible 5 UF']
),
'10UFDeductibleSM2Data': getProposalConditionsText(
solucionMovilDosProposals['Deducible 10 UF']
),
'15UFDeductibleSM2Data': getProposalConditionsText(
solucionMovilDosProposals['Deducible 15 UF']
),
'20UFDeductibleSM2Data': getProposalConditionsText(
solucionMovilDosProposals['Deducible 20 UF']
),
noDeductibleSMEData: getProposalConditionsText(
solucionMovilEstandarProposals['Sin Deducible']
),
'3UFDeductibleSMEData': getProposalConditionsText(
solucionMovilEstandarProposals['Deducible 3 UF']
),
'5UFDeductibleSMEData': getProposalConditionsText(
solucionMovilEstandarProposals['Deducible 5 UF']
),
'10UFDeductibleSMEData': getProposalConditionsText(
solucionMovilEstandarProposals['Deducible 10 UF']
),
'15UFDeductibleSMEData': getProposalConditionsText(
solucionMovilEstandarProposals['Deducible 15 UF']
),
'20UFDeductibleSMEData': getProposalConditionsText(
solucionMovilEstandarProposals['Deducible 20 UF']
),
noDeductibleSMM2Data: getProposalConditionsText(
solucionMovilMasDosProposals['Sin Deducible']
),
'3UFDeductibleSMM2Data': getProposalConditionsText(
solucionMovilMasDosProposals['Deducible 3 UF']
),
'5UFDeductibleSMM2Data': getProposalConditionsText(
solucionMovilMasDosProposals['Deducible 5 UF']
),
'10UFDeductibleSMM2Data': getProposalConditionsText(
solucionMovilMasDosProposals['Deducible 10 UF']
),
'15UFDeductibleSMM2Data': getProposalConditionsText(
solucionMovilMasDosProposals['Deducible 15 UF']
),
'20UFDeductibleSMM2Data': getProposalConditionsText(
solucionMovilMasDosProposals['Deducible 20 UF']
),
},
];
const pdf = await generate({
template: summaryPdfTemplate as unknown as Template,
inputs,
});
return Buffer.from(pdf.buffer);
}; |
Describe the bug
I have a google cloud function project and I installed packages @pdfme/generator and @pdfme/common to generate PDFs inside our google cloud functions. When building the project, an error occurs because it cannot find namespace 'React' on packages like:
The weird thing is that I only installed those two packages and did not installed other packages like for designing pdf's, pdf viewer or pdf form.
To Reproduce
I created a template, installed @pdfme/common and @pdfme/generator and tried to generate pdf with some inputs.
Expected behavior
I would expect the packages to not need React on backend.
Your Environment
Your Error Log
Additional context
There's another comparable issue, but the error and @pdfme versiones are not the same:
#447
The text was updated successfully, but these errors were encountered: