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

Terser + next 14 build error #21611

Closed
1 of 4 tasks
cyrus-za opened this issue Feb 5, 2024 · 9 comments
Closed
1 of 4 tasks

Terser + next 14 build error #21611

cyrus-za opened this issue Feb 5, 2024 · 9 comments
Assignees

Comments

@cyrus-za
Copy link

cyrus-za commented Feb 5, 2024

Current Behavior

I upgrade from nx 17.2.7 to nx 18.0.1 using nx migrate latest and running the migrations.
As part of this migration, my version for nextjs moved from 13.5.2 to 14.0.4

When I try to build my nextjs app I get the following error

Failed to compile.

834.js from Terser
Unexpected token: punc ({) [834.js: 4510,
    26
  ]
    at js_error (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 32780)
    at croak (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 43882)
    at token_error (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 43989)
    at unexpected (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 44055)
    at as_property_name (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 68487)
    at concise_method_or_getset (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 64746)
    at class_ (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 64098)
    at statement (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 46908)
    at _embed_tokens_wrapper (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 45013)
    at block_ (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 56881)

static/media/pdf.worker.b3692421.js from Terser
Unexpected token: punc ({) [static/media/pdf.worker.b3692421.js: 11809,
      26
    ]
    at js_error (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 32780)
    at croak (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 43882)
    at token_error (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 43989)
    at unexpected (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 44055)
    at as_property_name (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 68487)
    at concise_method_or_getset (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 64746)
    at class_ (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 64098)
    at statement (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 46908)
    at _embed_tokens_wrapper (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 45013)
    at block_ (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 56881)

475.js from Terser
Unexpected token: punc ({) [475.js: 135153,
        10
      ]
    at js_error (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 32780)
    at croak (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 43882)
    at token_error (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 43989)
    at unexpected (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 44055)
    at as_property_name (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 68487)
    at concise_method_or_getset (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 64746)
    at class_ (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 64098)
    at statement (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 46908)
    at _embed_tokens_wrapper (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 45013)
    at block_ (/node_modules/.pnpm/next@14.0.4_@babel+core@7.23.9_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/terser/bundle.min.js: 1: 56881)


> Build failed because of webpack errors
   Creating an optimized production build  .Error occurred while trying to run the build command
1

Related:
vercel/next.js#60837

Expected Behavior

build should not fail

GitHub Repo

No response

Steps to Reproduce

  1. nx migrate latest
  2. pnpm i
  3. nx build myApp

Nx Report

see logs

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@AgentEnder AgentEnder added the scope: nextjs Issues related to NextJS support for Nx label Feb 7, 2024
@ndcunningham ndcunningham self-assigned this Feb 9, 2024
@ndcunningham
Copy link
Contributor

ndcunningham commented Feb 9, 2024

I tried this out and it is working as expected.
Could this be related to your package manager

Could you create a small repro of this so I can take a look?

@cyrus-za
Copy link
Author

I tried this out and it is working as expected. Could this be related to your package manager

Could you create a small repro of this so I can take a look?

Do you use turbo or webpack? I think it is related to the SWC packages.

I'll try and do a repro

@cyrus-za
Copy link
Author

cyrus-za commented Feb 16, 2024

This seems to be the issue
vercel/next.js#61549

pnpm why pdfjs-dist
Legend: production dependency, optional only, dev only

dependencies:
react-pdf 7.3.1
└── pdfjs-dist 3.6.172

@cyrus-za
Copy link
Author

cyrus-za commented Feb 16, 2024

To reproduce this issue, using node 20, do the following:

  1. pnpx create-nx-workspace@latest
>  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Where would you like to create your workspace? · org
✔ Which stack do you want to use? · react
✔ What framework would you like to use? · nextjs
✔ Integrated monorepo, or standalone project? · integrated
✔ Application name · org
✔ Would you like to use the App Router (recommended)? · Yes
✔ Would you like to use the src/ directory? · Yes
✔ Test runner to use for end to end (E2E) tests · none
✔ Default stylesheet format · css
✔ Do you want Nx Cloud to make your CI fast? · skip
  1. pnpm add react-pdf@7.3.1
  2. Add the following code to next.config.js
{ 
  ...
  transpilePackages: ['react-pdf'],
  swcMinify: false,
  webpack: (config) => {
    config.resolve.alias.canvas = false;
    return config;
  },
  ...
}
  1. Add the following code to app/page.tsx
import 'react-pdf/dist/esm/Page/TextLayer.css'
import {  pdfjs } from 'react-pdf'

pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/legacy/build/pdf.worker.js', import.meta.url).toString()
  1. git diff apps/org
image
  1. npx nx run-many -t build

@cyrus-za
Copy link
Author

Downgrading to next 14.0.1 fixes it. Upgrading to 14.0.2 breaks it again. I can also see the build logs look completely different, so next must've changed the way they do builds in v14.0.2

@ndcunningham
Copy link
Contributor

I am not sure if this is a Nx-related issue.
I can leave this open for more discussion but as it stands I do not think it is caused by Nx.

@cyrus-za
Copy link
Author

It's a nextjs issue, but nx supports nextjs breaking changes with migrations, so I think it belongs here.

Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants