next.js: Build Fails with Terser: Invalid Unicode Code Point Error
Link to the code that reproduces this issue
https://github.com/PBnJson/reproduction-template
To Reproduce
- Set Up a Next.js Project: Use Next.js version 14.2.5 with next-pwa for PWA functionality.
- Configure next.config.js: Enable swcMinify and set experimental.newNextLinkBehavior to true.
- Run the Build Command: Execute npm run build.
- Observe the Error: Notice the build fails with a Terser error related to an invalid Unicode code point.
Current vs. Expected behavior
I expected the project to build and be minified but instead I had to disable minification with swcMinify:false in order to build successfully.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Home
Available memory (MB): 7954
Available CPU cores: 8
Binaries:
Node: 20.14.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 14.2.5
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Runtime, Script (next/script)
Which stage(s) are affected? (Select all that apply)
Other (Deployed)
Additional context
I’m deploying in Google Cloud vm instance with Debian. The app was working great before I added the service workers. The error happens at invalid unicode code point at line 1 column 43757 when I run docker compose up --build. Disabling swcMinify in next.config.js got the build to succeed, so some sort of minification issue.
- I was unable to reproduce the error in the
reproduction-template
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 26
- Comments: 25 (1 by maintainers)
Commits related to this issue
- Build: Use the 22.6 version of the Node image - Workaround for the building issue with the current version of Node image (node:current-alpine) by using the 22.6 version of the Node image (node:22... — committed to matheusmisumoto/workout-logger-web by matheusmisumoto 2 years ago
- still trying to fix the compiling issue related to nextjs issue https://github.com/vercel/next.js/issues/69263 — committed to cyphergurke/cypherweb by cyphergurke 2 years ago
This is caused by Node.js 22.7.0, downgrading to Node.js 22.6.0 fixes this error. See #69150
also happens to me but only when building docker image, which is weird. i’ve tried alpine, debian and even archlinux as base images, same error
my nextjs.config.js has nothing but rewrites in it
using next 14.2.5
node:lts-alpineis a good choice if you’re sticking withalpineto avoid using the latest version of Node.I choice to revisit the use of
alpineand found the recommendation given by Snyk in this article to be quite helpful.https://snyk.io/blog/choosing-the-best-node-js-docker-image/
Maybe it will help some of you to choose the most appropriate Node Docker image too.
The authors of the article suggested using
node:lts-bookworm-slimfor security and performance reasonsFWIW, I had no issues with my builds using Node version 20.17.0 up until 2 days ago, on August 23rd. Prior to that, deployments would succeed without this
invalid unicode code pointerror.So, it seems to be a very new issue with how strings are being parsed by Terser.
I tried downgrading to Node version 20.10.0 as suggested by @C3ntraX, but still no luck
I had the same issue. Seems like that the latest node version does not work with terser and will throw this wreid error.
I used node-version: “20.10.0” which works for me.
Yeah, I understand, but Sunday night is not the time for me to deal with this 😅
Catching the same problem - Nextjs 13.2.4 / Docker / Github actions / Nodejs slim 16
Tried versions 20.14.0 and 20.10.0 - did not solve the problem.
As a temporary solution I disabled swc in next.config.js.
Solution for me was switching from ‘node:bullseye’ -> ‘node:22.6-bullseye’ in the docker image.
node:bullseye started using 22.7.0 when it was available I guess and that made our pipeline explode
Had this problem with
node:alpineDocker image. Rolling back tonode:lts-alpinefixed it.It builds successfully in local, but fails in ci/cd process like github actions.
I solved this issue temporarily thanks to comment I replied. However, the
swcMinifyoption innext.config.mjswill be enabled by default and removed in Next.js 15. This issue must be resolved before Next.js 15 is released.I can confirm that the issue only happens when building my Next.js v14.2.6 app as a Docker image. I do not experience the error at all when I build my Next.js app locally; the build always fails in my GitHub Actions CI/CD script.
I was able to isolate the file which causes the issue; however, I haven’t made any significant changes since before this issue arose. That change is 3 lines which makes no use of string manipulation, only array filtering and the use of
.includeson a string.I would share the file, but I think it is unnecessary, given my previous sentence.
I think I’ve found a consistent way to trigger the error.
One of these lines triggers the error, other does not: https://github.com/eyenalxai/paste/blob/97e9821d709ff25e1ea7686a72aed9970a84a8af/lib/syntax/detect.ts#L34
To reproduce:
git clone https://github.com/eyenalxai/paste.git -b terser-error && cd pastedocker build -t paste:latest .This will result in an error.
Then, swap the comments on the lines as follows:
Run
docker build -t paste:latest .again, should build successfully.The same thing happened to me on when building Next.js on docker in Github Actions for Cypress E2E tests.
https://github.com/cypress-io/github-action?tab=readme-ov-file#docker-image
▲ Next.js 14.2.5
Creating an optimized production build … Failed to compile.
static/chunks/516-dd8f1e03298072f7.js from Terser invalid unicode code point at line 1 column 76631 Error: invalid unicode code point at line 1 column 76631