Skip to content
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

[NextJS] React-pdf 7.5.0 - Vercel deployment no longer works #1630

Closed
4 tasks done
w-aurelien opened this issue Oct 6, 2023 · 13 comments
Closed
4 tasks done

[NextJS] React-pdf 7.5.0 - Vercel deployment no longer works #1630

w-aurelien opened this issue Oct 6, 2023 · 13 comments
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@w-aurelien
Copy link

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

I just upgraded the version of react-pdf to version 7.5.0 and since then my deployments on Vercel are no longer working.

Steps to reproduce

My next.config.com

/** @type {import('next').NextConfig} */
const nextConfig = {
    experimental: {
        serverActions: true,
    },
    webpack: (config) => {
        config.resolve.alias.canvas = false;

        return config;
    },
}

module.exports = nextConfig

My Component :

'use client';

import {Box} from "@chakra-ui/react";
import React from "react";
import { Document, Thumbnail } from 'react-pdf';
import { pdfjs } from 'react-pdf';
import useResizeObserver from "use-resize-observer";

pdfjs.GlobalWorkerOptions.workerSrc = new URL(
  'pdfjs-dist/build/pdf.worker.min.js',
  import.meta.url,
).toString();

interface ThumbnailDocumentProps {
  ...
}

export function ThumbnailDocument({...}: ThumbnailDocumentProps) {
  const {ref, width = 1} = useResizeObserver<HTMLDivElement>();

  if (eventDocument.mimeType === 'application/pdf') {
    return <Box>
       <Document file={`/documents/${eventDocument.id}/visualiser/${eventDocument.originalName}?preview=1`}>
          <Thumbnail
            pageNumber={1}
            width={Math.max(width * 0.4, 100)} />
        </Document>
    </Box>;
  }
}

Expected behavior

Deployment completed :)
I want to reiterate that before upgrading the version, my deployments were working correctly.

Actual behavior

Vercel deployment error :

Error: File /vercel/path0/.next/server/chunks/static/media/pdf.worker.min.6a40b659.js does not exist.
--
10:17:32.381 | at Job.emitDependency (/vercel/path0/node_modules/next/dist/compiled/@vercel/nft/index.js:1:39473)
10:17:32.381 | at async Promise.all (index 10)
10:17:32.382 | at async nodeFileTrace (/vercel/path0/node_modules/next/dist/compiled/@vercel/nft/index.js:1:35430)
10:17:32.382 | at async /vercel/path0/node_modules/next/dist/build/collect-build-traces.js:251:28
10:17:32.383 | at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:105:20)
10:17:32.383 | at async collectBuildTraces (/vercel/path0/node_modules/next/dist/build/collect-build-traces.js:123:5)
10:17:32.500 | Error: Command "npm run build" exited with 1

Additional information

No response

Environment

  • React-PDF version: 7.5.0
  • React version: 18.2
@w-aurelien w-aurelien added the bug Something isn't working label Oct 6, 2023
@wojtekmaj
Copy link
Owner

What was the last version that worked for you?

@w-aurelien
Copy link
Author

What was the last version that worked for you?

7.3.3

@w-aurelien
Copy link
Author

I just realized that I also upgraded the version of nextJS, so I have just conducted the following deployment tests:

  • NextJS: 13.4.19 / React-pdf: 7.3.3: ✅
  • NextJS: 13.4.19 / React-pdf: 7.5.0: ✅
  • NextJS: 13.5.4 / React-pdf: 7.3.3: ❌
  • NextJS: 13.5.4 / React-pdf: 7.5.0: ❌

@wojtekmaj
Copy link
Owner

Well, that sounds like a Next.js problem to me then!

@w-aurelien
Copy link
Author

I think the two are related no? Maybe NextJs changed something that needs to be reflected in React-Pdf? Because if I remove react-pdf from my dependencies everything works correctly again.

@wojtekmaj
Copy link
Owner

Clearly something used to work and stopped working. That's a bug/regression by my standards. I'll be happy to assist Vercel should they pick it up.

@jerocosio
Copy link

Also getting the same error, it looks like the issue is on the latest version of Vercel NextJS: 13.5.4, as if I downgrade to NextJS: 13.5.3 I can deploy without any issues.

@JamesSingleton
Copy link

I just ran into this as well verifying everything built locally. The only thing that I could find that was "worker" related in 13.5.4 was vercel/next.js#55257 but not sure if that would cause any issues. 🤷🏼‍♂️

@sangdth
Copy link

sangdth commented Oct 10, 2023

I faced this issue, and found another closed issue with similar problem, one comment suggested using the worker from cdn url and it works. I will stick with it for now.

@yadhst
Copy link

yadhst commented Oct 10, 2023

I also got this problem before, i don't know if this is a good way or not, but the problem is solved.

I am using next.js version 13.5.4 and react-pdf version 7.5.0

// next.config.js
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");

const pdfjsDistDir = path.dirname(require.resolve("pdfjs-dist/package.json"));
const cMapsDir = path.join(pdfjsDistDir, "cmaps");
const standardFontsDir = path.join(pdfjsDistDir, "standard_fonts");
const pdfWorkerPath = path.join(pdfjsDistDir, "build", "pdf.worker.min.js");

/** @type {import('next').NextConfig} */
const nextConfig = {
    experimental: {
        serverActions: true,
    },
    webpack: (config) => {
        config.resolve.alias.canvas = false;

        config.plugins.push(
            new CopyWebpackPlugin({
                patterns: [
                    { from: cMapsDir, to: "static/chunks/pdfjs/cmaps/" },
                ],
            })
        );

        config.plugins.push(
            new CopyWebpackPlugin({
                patterns: [
                    {
                        from: standardFontsDir,
                        to: "static/chunks/pdfjs/standard_fonts/",
                    },
                ],
            })
        );

        config.plugins.push(
            new CopyWebpackPlugin({
                patterns: [
                    {
                        from: pdfWorkerPath,
                        to: "static/chunks/pdfjs/build/pdf.worker.min.js",
                    },
                ],
            })
        );

        return config;
    },
};

module.exports = nextConfig;
// in my pdf component
...
pdfjs.GlobalWorkerOptions.workerSrc =
    "/_next/static/chunks/pdfjs/build/pdf.worker.min.js";
const documentOptions = {
    cMapUrl: "/_next/static/chunks/pdfjs/cmaps/",
    standardFontDataUrl: "/_next/static/chunks/pdfjs/standard_fonts/",
};
...

@sangdth
Copy link

sangdth commented Oct 11, 2023

Thanks @yadh75, I tried your solution and so far it works well.

Btw what does the problem if we combine 3 pushes into one? I'm not really good at webpack:

        patterns: [
          { from: cMapsDir, to: 'static/chunks/pdfjs/cmaps/' },
          {
            from: standardFontsDir,
            to: 'static/chunks/pdfjs/standard_fonts/',
          },
          {
            from: pdfWorkerPath,
            to: 'static/chunks/pdfjs/build/pdf.worker.min.js',
          },
        ],

@yadhst
Copy link

yadhst commented Oct 11, 2023

Thanks @yadh75, I tried your solution and so far it works well.

Btw what does the problem if we combine 3 pushes into one? I'm not really good at webpack:

        patterns: [
          { from: cMapsDir, to: 'static/chunks/pdfjs/cmaps/' },
          {
            from: standardFontsDir,
            to: 'static/chunks/pdfjs/standard_fonts/',
          },
          {
            from: pdfWorkerPath,
            to: 'static/chunks/pdfjs/build/pdf.worker.min.js',
          },
        ],

there's no problem with that, in fact it's actually better that way

@wojtekmaj wojtekmaj added the invalid This doesn't seem right label Oct 13, 2023
@wojtekmaj
Copy link
Owner

Hey all, Vercel confirmed it's a bug on their side. I suggest following vercel/next.js#56676 for updates. There's nothing we can or should do on our side, so I'm closing this issue.

@wojtekmaj wojtekmaj closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

6 participants