2.0.21 causes create-react-app based app to crash on start
Aplietexe opened this issue · comments
Using the simple demo from the official webside:
import labelmake from "labelmake"
import { Template } from "labelmake/dist/types/type"
export const makePdf = async () => {
const template: Template = {
basePdf: { width: 210, height: 297 },
schemas: [
{
field1: {
position: { x: 20, y: 20 },
width: 50,
height: 50,
fontSize: 30,
type: "text"
},
field2: {
position: { x: 20, y: 35 },
width: 50,
height: 50,
fontSize: 20,
type: "text"
}
}
]
}
const inputs = [
{ field1: "aa", field2: "aaaaaaaaaaaa" },
{ field1: "bb", field2: "bbbbbbbbbbbb" }
]
const pdf = await labelmake({ template, inputs })
}
When running npm start:
Starting the development server...
<--- Last few GCs --->
[19636:0000020587757D70] 32697 ms: Scavenge 4043.8 (4135.2) -> 4036.8 (4135.5) MB, 4.5 / 0.0 ms (average mu = 0.225, current mu = 0.149) allocation failure
[19636:0000020587757D70] 35426 ms: Mark-sweep 4046.1 (4137.5) -> 4037.4 (4137.5) MB, 2724.3 / 0.0 ms (average mu = 0.138, current mu = 0.045) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF7D33C401F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112511
2: 00007FF7D3353146 DSA_meth_get_flags+65542
3: 00007FF7D3353FFD node::OnFatalError+301
4: 00007FF7D3C85ADE v8::Isolate::ReportExternalAllocationLimitReached+94
5: 00007FF7D3C7000D v8::SharedArrayBuffer::Externalize+781
6: 00007FF7D3B135FC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468
7: 00007FF7D3B202A9 v8::internal::Heap::PublishPendingAllocations+1129
8: 00007FF7D3B1D27A v8::internal::Heap::PageFlagsAreConsistent+2842
9: 00007FF7D3B0FEF9 v8::internal::Heap::CollectGarbage+2137
10: 00007FF7D3B0E0B0 v8::internal::Heap::AllocateExternalBackingStore+2000
11: 00007FF7D3B329E6 v8::internal::Factory::NewFillerObject+214
12: 00007FF7D3865C25 v8::internal::DateCache::Weekday+1797
13: 00007FF7D3D134B1 v8::internal::SetupIsolateDelegate::SetupHeap+494417
14: 0000020589D45C4B
- The makePdf function is located in a module that is imported, but the function itself is never called, yet it still causes the crash.
- Removing
const pdf = await labelmake({ template, inputs })
(but keeping the import) avoids the crash and allows the app to compile. - The code works fine in 2.0.20.
Not sure if the error is related to create-react-app or to webpack 5 in general.
Thanks for the report.
I created an environment to check the reproduction by the following code.
npx create-react-app my-app --template typescript
But could not reproduce it.
I think this error is not caused by labelmake, so I will close it.
Confirmed codes
import labelmake from "labelmake";
import { Template } from "labelmake/dist/types/type";
export const makePdf = async () => {
const template: Template = {
basePdf: { width: 210, height: 297 },
schemas: [
{
field1: {
position: { x: 20, y: 20 },
width: 50,
height: 50,
fontSize: 30,
type: "text",
},
field2: {
position: { x: 20, y: 35 },
width: 50,
height: 50,
fontSize: 20,
type: "text",
},
},
],
};
const inputs = [
{ field1: "aa", field2: "aaaaaaaaaaaa" },
{ field1: "bb", field2: "bbbbbbbbbbbb" },
];
const pdf = await labelmake({ template, inputs });
return pdf;
};
import "./App.css";
import { makePdf } from "./pdf";
function App() {
return (
<button
onClick={() => {
makePdf().then((pdf) => {
const blob = new Blob([pdf.buffer], { type: "application/pdf" });
window.open(URL.createObjectURL(blob));
});
}}
>
makePdf
</button>
);
}
export default App;
npm run build
serve -s build