Skip to content

Failing JSON parsing in Node 22 #3328

@stefan-garofalo

Description

@stefan-garofalo

EDIT
I managed to reproduce the error locally and changed the bug description, and reproduction steps accordingly

Bug Description

When making a fetch call the JSON parsing fails and spits out some broken chars. This only happens in Node 22.3.0, does not happen in node 22.1.0

Reproducible By

Fetching data from an API (in my case Wordpress) and parsing the body as json. Currently this happens in a Next.js project. When reaching my homepage I make a call to my cms

nvm use 22.3.0
async function call(url) {
  const response = await fetch(`${WP_DEFAULT_URL}${url}`, {});
  return response.json();
}

Expected Behavior

The JSON being parsed correctly. This behavior came up circa 3 days ago, I figure it has something to do with the latest Node 22.3.0 release

Logs & Screenshots

I added a trycatch to log the query if failing to see more clearly in the github logs, since I firstly bumped into the problem during a github action build

#9 28.25 SyntaxError: Unexpected non-whitespace character after JSON at position 2908 (line 1 column 2909)
#9 28.25     at JSON.parse (<anonymous>)
#9 28.25     at parseJSONFromBytes (node:internal/deps/undici/undici:5477:19)
#9 28.25     at successSteps (node:internal/deps/undici/undici:5459:27)
#9 28.25     at fullyReadBody (node:internal/deps/undici/undici:4378:9)
#9 28.25     at async consumeBody (node:internal/deps/undici/undici:5468:7)
#9 28.25     at async Object.getItem (/usr/src/app/.next/server/app/cerca/page.js:1:8661)
#9 28.25     at async o (/usr/src/app/.next/server/app/[lang]/(pages)/cerca/page.js:1:4250)
{... some other json from my cms...},
[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}]����!*�� �!*��ȉ!*��P�!*��x�!*����!*����.(�!*��@�!*���~!*�����y��@�!*����b������!*����!*�������L��c�*����c�*���`��*�����*���^����!*����!*���c�� �!*�� �!*����Ȋ!*��(�)*�������c�*����c�*���(�)*��� d�*��������L�
#9 28.25 ��
�
#9 28.25 ,����y�����y���������L�
#9 28.25 ��
�
#9 28.25 ,��
#9 28.25 D������t�0	�
#9 28.25 p���y�����y����g%8��y��8��y������3�����L�
#9 28.25 ��
�
#9 28.25 ,��
#9 28.25 D������t�0	�
#9 28.25 p� 	�H�8	����������
#9 28.25 ��������8��y��8��y����!*��?��������������������X��y��X��y���\�c�*����c�*���(�)*��� d�*���xd�*����d�*���xe�*����e�*���`��*�����*��0��*�����*����Ȋ!*���d�*��T�������L�
#9 28.25 ��
�
#9 28.25 ,��
#9 28.25 D������t�0	�
#9 28.25 p� 	�H�8	����������
#9 28.25 ��������H�0	�
#9 28.25 �����$�������%��
���������������	������� 
#9 28.25 ��!

Environment

Github worker using the latest Node 22.3.0 Docker image, but it also happens locally using the latest Node 22.3.0

Additional context

My application code did not change in such a timeframe, nor its configs. I managed to work around the issue and correctly publish my repository's images by downgrading to Node 20.

Since the stack trace refers to files inside /undici I figured issuing in this repository would have fit better rather than Node itself

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions