vercel / next.js

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

Template strings are incorrectly converted during building, lead to JSON.parse errors at production runtime. #70584

Open Innei opened 1 month ago

Innei commented 1 month ago

Link to the code that reproduces this issue

https://github.com/Innei/next-bundle-regexp-repro

To Reproduce

  1. clone my repro
  2. run build
  3. next start and see prod page

CleanShot 2024-09-28 at 9  01 11@2x

Current vs. Expected behavior

The product of the build has changed in structure from the third party's original file, specifically, the template string of the third party's original file has been converted incorrectly, resulting in a JSON parse error.

  1. The third party original code:

(It's too long. I've cut off part of it. CleanShot 2024-09-28 at 9  03 11@2x

I run the code, works

CleanShot 2024-09-28 at 9  04 09@2x

  1. next The compiled product, the template string is converted to a normal string, and throw an error.

CleanShot 2024-09-28 at 9  06 25@2x

And copy the JSON.parse part code and run in console. Error.

CleanShot 2024-09-28 at 9  07 23@2x

And in the actual run, the reported error is the same

CleanShot 2024-09-28 at 9  08 02@2x

I was expecting that. next.js should not be converting template strings. Not only is the conversion incorrect here, but it also doesn't respect browserlist, even though I've set the browserlist target to the last 1 chrome version.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.0.0: Mon Aug 12 20:52:12 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 22.3.0
  npm: 10.2.4
  Yarn: 1.22.21
  pnpm: 9.11.0
Relevant Packages:
  next: 14.2.13 // Latest available version is detected (14.2.13).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.6.2
Next.js Config:
  output: N/A

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

SWC

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

next build (local)

Additional context

No response

Innei commented 1 month ago

Link: https://github.com/vercel/next.js/issues/70500

Innei commented 1 month ago

https://github.com/shikijs/shiki/issues/784

fuma-nama commented 1 month ago

hmm isn't this a duplicate of https://github.com/vercel/next.js/issues/70500 (your linked issue)? Also it's fixed on Next.js 15 canary so I expect they will be porting the update to Next.js 14 soon or later