-
-
Notifications
You must be signed in to change notification settings - Fork 902
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
React-pdf 7 causes " exceeds the maximum size limit of 50mb" build error on Vercel #1504
Comments
Huh. Built your repo locally with React-PDF 7, and got cv.json of 269 B. |
Got this one as well, and I think it's caused by |
I had this problem too, because I imported the deps (Document, Page, pdfjs) into a NextPage which made them end up in the server bundle too. I solved it by extracting the PdfViewer and its deps into a different component and then lazy loading it into my NextPage. PdfViewer componentimport { type FC } from "react";
import { Document, Page, pdfjs } from "react-pdf";
import "react-pdf/dist/esm/Page/AnnotationLayer.css";
import "react-pdf/dist/esm/Page/TextLayer.css";
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
"pdfjs-dist/build/pdf.worker.min.js",
import.meta.url
).toString();
type PdfViewerProps = { file: File };
const PdfViewer: FC<PdfViewerProps> = (props) => {
const { file } = props;
return (
<Document file={file}>
<Page pageNumber={1} />
</Document>
);
};
export default PdfViewer; Import it like thisconst PdfViewer= dynamic(() => import("~/components/PdfViewer"), {
ssr: false,
}); CaveatFor this to work |
Next.js's |
I found a workaround to stop installing canvas if that might help? We add a new entry to the resolutions object in package.json for |
Any update on how to get around this? The lazy loading mentioned here does not fix the issue when I try to deploy to Vercel. |
I leveraged the same problem by adding resolutions in {
// Add the following config in package.json
"resolutions": {
"react-pdf/**/canvas": "link:./node_modules/.cache/null",
"pdfjs-dist/canvas": "link:./node_modules/.cache/null"
}
} The above config makes it not to install the large canvas package in Vercel serverless deployment. Wish it can help you too. |
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days. |
I am currently using this as a workaround: const PdfViewer = dynamic(() => import("./PDFViewer.component"), {
ssr: false
}); |
any new? |
For us the resolutions route did not work since we're workign with pnpm and package the app differently. When you look at the original issue here, it is that canvas is being packaged on server side code when for most cases here people are loading it dynamically on the client side. To avoid it being packaged, we added an experimental setting on our next.config.js file For our case specifically we're using pnpm, but your node_modules path to canvas will look differently, just check the output logs for your build and you'll see the tracing outputs that are large. You can safely exclude them here if you're only using them on the client side.
|
This worked for me, thanks! I wish I'd seen it after I'd already spent 3 hours banging my head against the wall but I guess that's just the Next.js life For npm in case it's not obvious
|
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days. |
This issue was closed because it has been stalled for 14 days with no activity. |
Before you start - checklist
Description
After trying to upgrade to React-pdf version 7 I am getting build errors on Vercel.
Error: The Serverless Function "_next/data/RGgqgLBLLHa65oFs5xGa9/nb-NO/cv.json" is 59.02mb which exceeds the maximum size limit of 50mb. Learn More: https://vercel.link/serverless-function-size NOW_SANDBOX_WORKER_MAX_LAMBDA_SIZE: The Serverless Function "_next/data/RGgqgLBLLHa65oFs5xGa9/nb-NO/cv.json" is 59.02mb which exceeds the maximum size limit of 50mb.
The PDF renders fine locally in
npm run dev
Downgrading to version 6 fixes the error
Steps to reproduce
Expected behavior
I expect no build errors
Actual behavior
Error: The Serverless Function "_next/data/RGgqgLBLLHa65oFs5xGa9/nb-NO/cv.json" is 59.02mb which exceeds the maximum size limit of 50mb. Learn More: https://vercel.link/serverless-function-size
NOW_SANDBOX_WORKER_MAX_LAMBDA_SIZE: The Serverless Function "_next/data/RGgqgLBLLHa65oFs5xGa9/nb-NO/cv.json" is 59.02mb which exceeds the maximum size limit of 50mb.
Additional information
Environment
The text was updated successfully, but these errors were encountered: