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

@react-pdf/renderer doesn't work with swcMinify set to true. #40803

Closed
1 task done
bryanprimus opened this issue Sep 22, 2022 · 3 comments · Fixed by #40928
Closed
1 task done

@react-pdf/renderer doesn't work with swcMinify set to true. #40803

bryanprimus opened this issue Sep 22, 2022 · 3 comments · Fixed by #40928
Assignees
Labels
bug Issue was opened via the bug report template.

Comments

@bryanprimus
Copy link

bryanprimus commented Sep 22, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

next info

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Home Single Language
    Binaries:
      Node: 16.13.2
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.3.1
      eslint-config-next: 12.3.1
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

Tested on Chrome, Firefox, and Brave

How are you deploying your application? (if relevant)

vercel

Describe the Bug

I'm using @react-pdf/renderer to create pdfs from react app.

It's all working fine as expected in the development environment, but when I build the app

and visit the page with pdf created by @react-pdf/renderer I got this error

image

I thought this was because I'm using react 18 and there's an issue in @react-pdf/renderer that says to add support with react 18 diegomura/react-pdf#2020.

I try downgrading with this step https://stackoverflow.com/a/71972096/12720875. and it did work when I built the app with no error. But It is still at the latest using next12.1.2, and when upgrading to the latest nextjs the error appears again, and I need the feature of the latest nextjs.

and then i noticed that the error message says it's related to minification issue.

image

then I'm headed to next.config.js and remove swcMinify: true. and when I build the app and visit the pdf page. The error disappears.

I mean the error was already resolved by doing so. But I will not get the advantage of minification of swc. Also, I am still confused about what happened. And since the swcMinify is already stable as per next 12.3.0 i think this shouldn't happen.

Expected Behavior

There's no error with the production build result

Link to reproduction

https://github.com/bryantobing12/next-pdf-repro

To Reproduce

Steps to reproduce

  1. git clone https://github.com/bryantobing12/next-pdf-repro
  2. yarn to install deps
  3. yarn build
  4. yarn start
  5. visit localhost:3000/test
  6. The app will crash with error messages in the console

I was able to resolve that by removing swcMinify: true in next.config.js

steps

  1. remove swcMinify: true in next.config.js
const nextConfig = {
  reactStrictMode: true,
-  swcMinify: true,
};
  1. yarn build
  2. yarn start
  3. visit localhost:3000/test
  4. The app will show the pdf preview with no error in the console

I'm hoping that this could be resolved without turning off swc minification :)

@bryanprimus bryanprimus added the bug Issue was opened via the bug report template. label Sep 22, 2022
@kdy1 kdy1 self-assigned this Sep 26, 2022
@kdy1
Copy link
Member

kdy1 commented Sep 27, 2022

Fixed by swc-project/swc#5954

image

I'll create a PR soon.

kdy1 added a commit to swc-project/swc that referenced this issue Sep 27, 2022
**Description:**

Although the author of the issue talked about `@react-pdf/renderer`, it's a bug related to `brotli`, not react pdf renderer.

After investigation, I found that the bug is caused by not marking parameters as initialized. So I fixed the analyzer.

**Related issue:**

 - vercel/next.js#40803.
ijjk pushed a commit that referenced this issue Sep 27, 2022
This PR updates swc crates to
swc-project/swc@3d393dd

---

This PR applies

 - swc-project/swc#5954

Closes #40803

 - swc-project/swc#5956

Resolves
#30237 (comment)
@bryanprimus
Copy link
Author

Thanks for the fix @kdy1

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants