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

Fetching error: UND_ERR_REQ_CONTENT_LENGTH_MISMATCH #32

Open
rodriabregu opened this issue Dec 2, 2024 · 1 comment
Open

Fetching error: UND_ERR_REQ_CONTENT_LENGTH_MISMATCH #32

rodriabregu opened this issue Dec 2, 2024 · 1 comment

Comments

@rodriabregu
Copy link

rodriabregu commented Dec 2, 2024

There is a (currently closed) issue with the use of Fetch inside NextJS as NextJS wraps the default fetch with its own implementation, which also happens in xior.

Sometimes in build-time and run-time use can generate this type of error:

[11:31:47.257] TypeError: fetch failed
[11:31:47.257]     at Object.fetch (node:internal/deps/undici/undici:11576:11) {
[11:31:47.257]   cause: RequestContentLengthMismatchError: Request body length does not match content-length header
[11:31:47.257]       at AsyncWriter.end (node:internal/deps/undici/undici:10355:19)
[11:31:47.258]       at writeIterable (node:internal/deps/undici/undici:10263:16) {
[11:31:47.258]     code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
[11:31:47.258]   }
[11:31:47.258] }

In my case, locally I have not been able to reproduce it, however in a project deployed in Docker is where I have had the problem in run-time use (With a custom Content-Length or not).

The is the issue I mentioned: Nextjs Issue

Xior version: 0.6.1, Next.js version: 15.0.2.

@suhaotian
Copy link
Owner

suhaotian commented Dec 2, 2024

From the error message, Maybe check the code where put the content-length in headers or where put headers from request,

But due to Next.js already fixed the fetch issue, you can check here for Request body length does not match content-length header/UND_ERR_REQ_CONTENT_LENGTH_MISMATCH error:

vercel/next.js#55410

Also, you can add below code to check the error from which endpoint:

import xior from 'xior';

const http = xior.create();

http.plugins.use((adapter, instance) => {
  return async (config) => {
    try {
      return adapter(config);
    } catch (error: any) {
      console.log(`${config.method} ${config.url} error:`, error, config);
      throw error;
    }
  };
});

Thanks for reporting this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants