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

Upgrading to 13.3.0 cause SyntaxError: Unexpected token u in JSON at position 0 #48070

Closed
1 task done
XEngine opened this issue Apr 7, 2023 · 48 comments
Closed
1 task done
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template.

Comments

@XEngine
Copy link

XEngine commented Apr 7, 2023

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

@XEngine XEngine added the bug Issue was opened via the bug report template. label Apr 7, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label Apr 7, 2023
@Kamalito75
Copy link

I have the same problem even without using "use client".

@micmc422
Copy link

micmc422 commented Apr 7, 2023

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”

@guttir14
Copy link

guttir14 commented Apr 7, 2023

Similar issue: #47704

@pier7529
Copy link

pier7529 commented Apr 7, 2023

After upgrading to 13.3.0 : same error - SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse ()

sur OS Windows 11 (22H2)

Downgrade the Next.js version to 13.2.4 works for me.

@NitrousBGC
Copy link

NitrousBGC commented Apr 7, 2023

Same problem here on all pages (13.3.1-canary.0)

@VaniaPopovic
Copy link

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 ()

@AmeenJalali
Copy link

AmeenJalali commented Apr 7, 2023

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.

@getfit-us
Copy link

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.

@leonlarsson
Copy link

+1
Happens on 13.3.0 with https://github.com/leonlarsson/bfstats-web

@lenryk
Copy link

lenryk commented Apr 7, 2023

Only happens when I use use client for pages.

Rolled back next to v13.2.4 and seems to work now. Hopefully, they will fix it soon for the latest release.

@schimi-dev
Copy link

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.

@Xetoxyc
Copy link

Xetoxyc commented Apr 7, 2023

already discussed here, also there was a revert from @feedthejim. Seems like they could not reproduce it at review.

#47736

@GetPsyched
Copy link

I do not have this issue (Linux, Next v13.3) however my friend who has the exact same repo as me (Windows 11, Next v13.3.0) does have this issue.

I've seen others in this thread mention Windows; perhaps it's a Windows + v13.3.0 problem?

@GetPsyched
Copy link

GetPsyched commented Apr 8, 2023

@XEngine I believe the u is from undefined being passed into JSON.parse here:

// node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js

function parseModel(response, json) {
  return JSON.parse(json, response._fromJSON);
}

This is what causes the syntax error since undefined isn't valid JSON.

@jacobkapitein
Copy link

The issue seems to only happen on Windows. A temporary workaround would be to use WSL. That seems to work for me.

@XEngine
Copy link
Author

XEngine commented Apr 8, 2023

@XEngine I believe the u is from undefined being passed into JSON.parse here:

// node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js

function parseModel(response, json) {
  return JSON.parse(json, response._fromJSON);
}

This is what causes the syntax error since undefined isn't valid JSON.

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 :D

@alfredlwanzo
Copy link

Same issue. 13.3.0 does not support 'use client'

@microdotmatrix
Copy link

I do not have this issue (Linux, Next v13.3) however my friend who has the exact same repo as me (Windows 11, Next v13.3.0) does have this issue.

I've seen others in this thread mention Windows; perhaps it's a Windows + v13.3.0 problem?

I 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.

@TheMagoo73
Copy link

TheMagoo73 commented Apr 8, 2023

I'm seeing the same issue with my toy project - https://github.com/TheMagoo73/pokematic. main branch 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.

@ArianHamdi
Copy link
Contributor

Resolved by enabling turbopack.
seems a webpack issue.
Windows 11, node 16.19.0.

@moolcoov
Copy link

moolcoov commented Apr 9, 2023

Same issue

@ghost
Copy link

ghost commented Apr 9, 2023

We're having this same error for last 2 days on windows only, working fine on linux and mac, as everyone else mentioned JSON is recieving undefined in here -
image

@ghost
Copy link

ghost commented Apr 9, 2023

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.

@TheMagoo73
Copy link

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.

@XEngine
Copy link
Author

XEngine commented Apr 9, 2023

changing them to arrow components not a fix for me.

@moolcoov
Copy link

moolcoov commented Apr 9, 2023 via email

@XEngine
Copy link
Author

XEngine commented Apr 9, 2023

#47704 (comment)

this appears to be a greak workaround for now. Closing this since this solution is a PR now and it will probably on the next canary release

@XEngine XEngine closed this as completed Apr 9, 2023
@GMBermeo
Copy link

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.

Worked for me, thanks.

@beratbayram
Copy link

beratbayram commented Apr 11, 2023

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.

@moolcoov
Copy link

moolcoov commented Apr 11, 2023

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.

this issue was resolved in v13.3.1-canary.4

@2akb
Copy link

2akb commented Apr 11, 2023

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

@sawa-ko
Copy link

sawa-ko commented Apr 11, 2023

Fixed with latest canary version (13.3.1-canary.4). :D

@maddsua
Copy link

maddsua commented Apr 12, 2023

Resolved by enabling turbopack. seems a webpack issue. Windows 11, node 16.19.0.

yep, turbopack works fine

@rafaelbvc
Copy link

rafaelbvc commented Apr 13, 2023

After i use "use client" i got type n parse errors...
Mine NextJS V13.3.0, arrow function worked!

@nathanelcorpuz
Copy link

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.

Turning it into an arrow function and exporting that as default worked for me. Thank you.

@Venipa
Copy link

Venipa commented Apr 13, 2023

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.

this issue was resolved in v13.3.1-canary.4

fyi
still an issue in v13.3.1-canary.6

edit:
this
image

@anargiris
Copy link

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.

@asheikho99
Copy link

asheikho99 commented Apr 14, 2023

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.

It will stop working if you have a named export along side default export in your file. also it appears that the issue occurs with named exports

Working

'use client';

import { signIn } from 'next-auth/react';

const LoginButton = () => {
    return (
        <button
            onClick={() => {
                signIn('github');
            }}>
            Sign In
        </button>
    );
};

Not Working

'use client';

import { signIn, signOut } from 'next-auth/react';

const LoginButton = () => {
    return (
        <button
            onClick={() => {
                signIn('github');
            }}>
            Sign In
        </button>
    );
};

const LogoutButton = () => {
    return (
        <button
            onClick={() => {
                signOut();
            }}>
            Sign Out
        </button>
    );
};

export default LoginButton;
export { LogoutButton };

@rohansen856
Copy link

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.

Thanks. It worked.

@burakyesilyurt
Copy link

I've fixed it this way.

"use client";
import { useEffect, useState } from "react";

const TestComponent = () => {    //---------------> make an arrow function

const [counter, setCounter] = useState(0);

  useEffect(() => {
    const interval = setInterval(() => {
      setCounter((prevCounter) => prevCounter + 1);
    }, 1000);
    return () => clearInterval(interval);
  }, []);

 return (
    <div className="App">
      <h1>Counter: {counter}</h1>
    </div>
  );
}
export default TestComponent    //---------------> export from here

@beratbayram
Copy link

I confirm that it is fixed for me at v13.3.1-canary.4

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.

this issue was resolved in v13.3.1-canary.4

rayokamoto added a commit to compsci-adl/website that referenced this issue Apr 20, 2023
Next.js 13.3.0 has a bug with the compilation stage that raises an error
about JSON parsing.

See vercel/next.js#48070
@Satindar31
Copy link

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 --turbo flag when starting

@itava0
Copy link

itava0 commented Apr 21, 2023

I'm using Windows 11 and nextJS 13.3.0
Arrow functions fixed the issue for me.

@itava0
Copy link

itava0 commented Apr 21, 2023

Spend two days debugging these issues 😭

@timootten
Copy link

Found out it didnt worked for me, because I use a wrapper.

image
image

@timootten
Copy link

Doesn't worked:

image
In different file:
image

Worked in same file:
image

@JaviVA93
Copy link

JaviVA93 commented May 4, 2023

I updated to version "13.3.1-canary.4" and now it's fixed (no need to do the arrow function workaround, which didn't always work)

@github-actions
Copy link
Contributor

github-actions bot commented Jun 4, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests