-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
[NEXT-940] Unexpected token u in JSON because of "use client" #47704
Comments
Same problem in our project using 13.2.5-canary.21. It works fine on Linux but not on Windows. We're seeing the problem with |
On 13.2.4 with a page that uses a client component. When I migrate the page to a route group with a multiple root layouts I also get this error. Tested on canary as well. On Windows. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Have y'all tested this on Node LTS as well? Because I haven't seen this issue before and since you're on Node 16 it could be worth a try. |
Tried it on Node 18 and still the same error. |
Likewise updated node and that doesn't fix it. Additionally |
found the issue, you're using a fragment in your client page which throws a server mismatch in both dev and build.
Don't mind the arrowfunction swap instead of a regular function, has to do with my dev setup where I autoswap react components/pages etc to arrow function. See the repo below: https://github.com/JesseKoldewijn/nextjs13-appDir-staticExport My next info output:
|
@JesseKoldewijn This solution didn't work for me. Did it work for anyone with this issue? Windows, node 18.12.1, next 13.2.4 Edit: Just managed to solve my issue. I was exporting JSX through an async function, must have been a copy pasta. |
I am experiencing the same issue here for Versions 13.2.5-canary.20 through to 13.2.5-canary.25 13.2.5-canary.19 works fine. |
This is just too huge of a bug to be left unoticed by the next team. So I believe we must fall under certain conditions to let this error happen. From every person that commented here, I would like to know your operating system, node version and any other detail considered relevant. |
The same on any canary> 20. Win 11, Node v18.15.0 |
For me not using the arrow function broke it.
Swapped my client component to an arrow function and it worked. |
Yeah for me it sort of stopped breaking on build when I used arrow functions and actually having a element in the return other than a empty fragment. It did still break on a dynamic route tho cuz on the static build it only exported images used in one of the static routes and nothing else. So it only exports the following structure:
The disfunctional dynamic route might have to do with my setup because I didn't dive deep into the ssg usecase of it yet, so I'm not sure if you still have to generate the static paths for it. The disfunctional image src hrefs on the index page are kinda weird to me because I'm not using anything in the homepage that scream "I'm gonna break!" to me honestly. Might need to have a deeper look into it bur hey, atleast it partially works ish. Repo: https://github.com/ShiftCodeEU/shiftcode.eu ^ Incase anybody knows what the deal is with the broken images or something, would appreciate it👌 Ps. Sorry for the whole essay😅 |
Same here, switching my client component to an arrow function instead of a regular function fixed the build error, didn't change anything else: --- edit --- It is however strictly coupled to using a regular function inside a --- second edit --- |
I edited all of my client components and changed to Arrow functions which partially solved the issue. I am using Vercel's Analytics wrapper which has the format: ` export function AnalyticsWrapper() { When I change this to an arrow function everything breaks. The same for the preview Suspense that I am using for my Sanity CMS integration. `"use client" // Once rollup supports 'use client' module directives then 'next-sanity' export { PreviewSuspense as default } from 'next-sanity/preview';` I try to keep up with the Canary releases.....for exactly this reason, when things break I like to stay ahead a little, rather than trying to upgrade higher versions of releases which has been problematic in the past. |
Error still happening in |
If anyone is in a position where others on your team have Windows and you only have a mac, I used this app, downloaded Node, and was able to debug our codebase / try the suggestions above. |
Wish vercel/next team would look into this, because Im unable to test fixes and later improvements because of this error. |
I had all my functions as arrow functions and with export default. One page had |
This is not just related to pages, every component with Reproduction:
"use client"
export const ClientComponent = () => {
return (<div>Hello World</div>)
}
<body>
{children}
<ClientComponent/>
</body> This results in This is also affecting |
It's related to two files, changed in 13.2.5-canary.20. dist\build\analysis\get-page-static-info.js |
Remove Maybe
|
This error occurs when the clientEntryType is
Maybe some problem with moduleProxy in windows. |
Is the team aware about this? |
Confirmation of arrow functions working- I'm using Windows - 10 and node 19.7.0 |
It's path backslash and string escape bug at next-flight-loader, in Windows
Possible solutions
I am not sure arrow function's workaround is the same problem as this. Is there anyone patch node_modules\next\dist\build\webpack\loaders\next-flight-loader\index.js, this file. then delete .next directory, restart dev. |
Works for me, huge thanks! |
@motopods Thank you! It's working like a charm because for me, using the Arrow function cannot fix the problem because external libraries like NextAuth Session Provider are invoked and the problem still exists. |
Amazing find @motopods! Works great on the newest versions. Having said that, I am not sure how the arrow function trick seems to solve it in some cases (it didn't fully solve it in mine), so worth investigating further and hopefully, an official patch will come soon now |
converting to arrow function fixed the issue for me in 13.3.0. |
To avoid a bug (vercel/next.js#47704) switched all components to arrow functions (will revert once it's solved).
* Update site to v1.0.4 (#15) * Refactor cleanup (#10) * Refactor Cleaned some unused imports * Update SocialLinks.jsx Added a key for each child on the list. * Changed height to be atleast the screen's height (#11) * 8 Projects button fix (#12) * Moved header to its own component * Update Header.jsx Fixed #8 * Update Navbar.jsx Deleted commented import * Update About.jsx (#14) Added margint at the top to avoid the title ending behind the menu. * Update project to v1.0.4 (#17) * Update package.json (#16) Updated project versión to v1.0.4 * Installed TypeScript * Update tsconfig.json TypeScript configuration * Update .prettierrc * Update .gitignore * Eslintr config * /app -> TypeScript * /components -> TypeScript * Upgrade to NextJS v13.3.x * Upgrade to NextJS v13.3.x * Deleted deprecated package * Update .eslintrc.json * Added types for react-scroll * HTML fix Fixed names on HTML tags for react-scroll to work * Components to arrow functions To avoid a bug (vercel/next.js#47704) switched all components to arrow functions (will revert once it's solved). * Scroll fix * Update package.json Updated project to v1.1.0
Thank you! This is working for me as well ❣️ I didn't need to convert to arrow functions either. I'm on Windows 11 and Node v18.12.1 |
This is working for me as well. |
Thanks it worked for me! |
### What? It's path backslash and string escape bug at [next-flight-loader](https://linear.app/vercel/issue/NEXT-flight-loader), in Windows ### Why? ### How? Closes NEXT-940 Fixes #47704
Thanks @shuding, really grateful for this |
same problem.... |
@AlexKaridas Does this solution work for you? |
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. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Static HTML Export (next export)
Link to the code that reproduces this issue
https://github.com/thewbuk/nextjs13_error
To Reproduce
npm run build
Describe the Bug
When trying to build project,
SyntaxError: Unexpected token u in JSON at position 0
is thrown for every page that uses"use client"
even though the latest release of the canary is supposed to fix this issue.Using
App
directoryExpected Behavior
Create static export
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
NEXT-940
The text was updated successfully, but these errors were encountered: