vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.18k stars 26.74k forks source link

Swc causing error in production. Related to citation-js and citeproc. #69150

Open igloo1505 opened 1 month ago

igloo1505 commented 1 month ago

Link to the code that reproduces this issue

https://github.com/igloo1505/ulldApp

To Reproduce

I'm building two separate but related projects that are intended to work together. One is a large monorepo, the other is a single Next app currently on 14.2.5. You can clone the single app at the repo here, but it will require an appConfig.ulld.json file at the root of that project that would look something like appConfig.ulld.json to build and run without blowing up.

Current vs. Expected behavior

The app would produce an error that was related to one of citation-js's dependencies, citeproc which was apparently generated by swc. It ran flawlessly in development, but output this error in production:

TypeError: Cannot read properties of undefined (reading 'name')
    at t.XmlJSON.addMissingNameNodes (/Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/.next/server/chunks/34354.js:17:43244)
    at new t.Engine (/Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/.next/server/chunks/34354.js:17:67469)
    at u (/Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/.next/server/chunks/34354.js:1:373946)
    at c (/Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/.next/server/chunks/34354.js:1:374213)
    at bibliography (/Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/.next/server/chunks/34354.js:1:374923)
    at tl (/Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/.next/server/chunks/34354.js:1:28027)
    at g.tm [as format] (/Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/.next/server/chunks/34354.js:1:28107)
    at d (/Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/.next/server/chunks/34354.js:17:2746)
    at async v (/Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/.next/server/app/api/events/onSync/route.js:1:12672)
    at async /Users/bigsexy/Desktop/current/ulldSandbox/ulldApp/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36258

Disabling swc with swcMinify: false resolved the issue, but I'm posting here so that you're aware for next@15.x.x when that option won't be available.

There was a related issue submitted by the citation-js author here, but it was close due to inactivity.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:34 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.4.1
  npm: 10.8.1
  Yarn: 4.3.1
  pnpm: 9.7.1
Relevant Packages:
  next: 14.2.5 // Latest available version is detected (14.2.5).
  eslint-config-next: 14.2.5
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.5.4
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Runtime, SWC

Which stage(s) are affected? (Select all that apply)

next build (local), next start (local)

Additional context

No response

jonluca commented 1 month ago

CleanShot 2024-08-23 at 12 59 33@2x

We're also seeing this issue as well for what its worth. Disabling swcMinify fixes it.

darthmaim commented 1 month ago

@jonluca The invalid unicode point error is caused by Node.js 22.7.0, downgrading to Node.js 22.6.0 fixes that error. This is not caused by Next.js.

jonluca commented 1 month ago

That would do it! thanks @darthmaim

RaenonX commented 1 month ago

@jonluca The invalid unicode point error is caused by Node.js 22.7.0, downgrading to Node.js 22.6.0 fixes that error. This is not caused by Next.js.

This is a life saver because all my new builds are failing deterministically and I am scrathcing head finding the root cause, only to notice that it's node new version release breaking it.

I have filed https://github.com/nodejs/node/issues/54532 so hopefully node.js team can fix it.

ncostaramos commented 3 weeks ago

Got Tenser errors with node.js -v 22.7.0.

No error when using node.js -v 20.17.0.

kdy1 commented 3 weeks ago

Did you try the latest canary?

kdy1 commented 3 weeks ago

I can't run your repro because of ulldBuildData.json".

crazyWolf-cz commented 2 weeks ago

Node 22.8. fixed this 🥳

lightify97 commented 1 week ago

@crazyWolf-cz Just experienced this with v22.8.0 (Next v14.2.11)

kdy1 commented 3 days ago

Can you try 15 canary? I couldn't backport the SWC minifier because of some Rust-side restrictions related to swc_core, but those issues should be fixed already in the upstream.