next.js: Upgrading to 13.3.0 cause SyntaxError: Unexpected token u in JSON at position 0
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 18.12.1
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 13.3.0
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
can’t provide, big project, anyways it only occurs on some environments maybe, couldn’t reproduce on stackblitz
To Reproduce
:>
Describe the Bug
When I put “use client” at the top of a file next begins to cry about " SyntaxError: Unexpected token u in JSON at position 0".
13.2.4 didn’t have this issue.
Expected Behavior
nextjs should not cri about “u” in “use client”.
Which browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 48
- Comments: 48 (2 by maintainers)
It can be fixed by simply turning your normal function () {} components into arrow function components whereever you’ve used “use client” you must use arrow function, it’s still a bug but it can be fixed by using arrow functions. I’ve fixed it myself and several others from a different issue fixed their projects this way. Until the bug is fixed this should work.
I confirm the words of my predecessor - after installing the nextjs package and before the first run, install: npm install --save next@13.3.1-canary.4 react react-dom
this issue was resolved in v13.3.1-canary.4
changing them to arrow components not a fix for me.
After upgrading to 13.3.0 : same error - SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>)
sur OS Windows 11 (22H2)
Downgrade the Next.js version to 13.2.4 works for me.
Only happens when I use
use clientfor pages.Rolled back next to
v13.2.4and seems to work now. Hopefully, they will fix it soon for the latest release.Same here on win11, seem to be every folders/files starting with “u”. I got a folder "ui”, files in trigger error if I change to “fix-ui” error is from a file starting with “use client”.
Error from folder : “Module parse failed: Bad character escape sequence”
I confirm that it is fixed for me at v13.3.1-canary.4
I’ve fixed it this way.
Resolved by enabling turbopack. seems a webpack issue. Windows 11, node 16.19.0.
I have the same issue, but working great on 13.2.4. Big Project Can not really share either. I am back at 13.2.4 everything working fine.
I have the same problem after upgrading to 13.3.0. “Only Checked with Windows 11”. Tried to downgrade Next.js version to 13.2.4, removing node_modules and package-lock.json and re-installing modules doesn’t work.
Everything was working properly with 13.2.4, I don’t know what happened after I upgraded to 13.3.0. Downgrading to 13.2.4 not working and still got “SyntaxError: Unexpected token u in JSON at position 0” error.
Downgrade the Next.js version to 13.2.0 works for me.
This error only appears on a Windows machine for me only on NextJS > (13.2.4). Tried Node 18.15, and the latest current 19.8.1. Also tried installing dependancies with NPM (latest) and PNPM (latest). My project runs fine on my mac machine, without
error - SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse ()This only happens in the 13.3 update. It is related to an issue in parsing
'use client. A simple work around is using the--turboflag when startingI was running into this problem when I updated to 13.3 in a project I was working on in Windows 10 on my laptop, and after reading through this issue thread I booted my desktop running Linux (Ubuntu 22.04), run a fresh create-next-app package with 13.3 and unfortunately I’m still having this issue… so no, its a problem on Linux as well. At least it is for me.
Same problem here. It worked fine until v13.2.5-canary.19. Starting from v13.2.5-canary.20 I get this problem on my Windows machine.
I have the same issue when I try to wrap my app with the SupabaseProvider from this example: https://supabase.com/docs/guides/auth/auth-helpers/nextjs-server-components
Don’t know if my problem is related to Supabase or NextJS but I guess it could be useful to share this here. Tested both with 13.3 and 13.2.4 and still got the same problem.
Turning it into an arrow function and exporting that as default worked for me. Thank you.
After i use “use client” i got type n parse errors… Mine NextJS V13.3.0, arrow function worked!
Arrow function fix did not work for me. I had to rollback to 13.2.4.
I can confirm that the issue occurs when “use client” is used and I am also using a win 10 machine with default configurations.
Changing my client components to use arrow function seems to have worked around this. I haven’t been able to migrate to TurboPack yet as it seems to break the optional catch-all route at the root of my app, but it seems (at least for me) using arrow functions for client components is the key.
I’m seeing the same issue with my toy project - https://github.com/TheMagoo73/pokematic.
mainbranch using 13.2.4 is working just fine, but locally I get this issue after upgrading to 13.3.0 in https://github.com/TheMagoo73/pokematic/tree/next-version. This is on my Win10 dev box.Deploying the 13.3.0 branch out to Vercel as a preview (ie. the version that fails locally) works just fine.
yes I also found this block, there is one function that called this function while its argument called “model” or someting was null. I am just not familier with next’s source which is all rust or something otherwise I would try to create a PR 😄
@XEngine I believe the
uis fromundefinedbeing passed intoJSON.parsehere:This is what causes the syntax error since
undefinedisn’t valid JSON.