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

With Next.js13 app-directory, Fetch API cause error when optional argument set #36

Closed
ebifran opened this issue Nov 29, 2022 · 5 comments · Fixed by #89
Closed

With Next.js13 app-directory, Fetch API cause error when optional argument set #36

ebifran opened this issue Nov 29, 2022 · 5 comments · Fixed by #89

Comments

@ebifran
Copy link

ebifran commented Nov 29, 2022

Here is my app/page.tsxcode.(experimental-edge is enabled)

export default async function Page() {
  // OK
  const json = await fetch("https://jsonplaceholder.typicode.com/todos/1").then(
    (res) => res.json()
  );

  // Error
  const json = await fetch("https://jsonplaceholder.typicode.com/todos/1", {
    method: "GET",
  }).then((res) => res.json());

  return (
    <>
      <p>{json.userId}</p>
      <p>{json.title}</p>
    </>
  );
}

image

@pksorensen
Copy link

I can confirm the same thing, the error is related to the generated worker.js
Running site locally with wrangler gave me

(error) Error: Failed to get the 'mode' property on 'Request': the property is not implemented.

 at Request.get integrity [as integrity] (/usr/local/lib/node_modules/wrangler/node_modules/@miniflare/core/src/standards/http.ts:453:12)
    at a (/usr/src/app/.vercel/output/static/_worker.js:1968:132)

so a few manual fixes removing those things that it cannot get moved it past those errors.

              var s = JSON.stringify([a2.method, Array.from(a2.headers.entries()), a2.redirect, a2.referrer, a2.referrerPolicy]);

but now i am stuck at

TypeError: Failed to parse URL from https://..../api/entities/accounts?$count=true&$top=0&$filter=accounttype/name eq '....'&$select=name,createdon
    at new Request (/usr/local/lib/node_modules/wrangler/node_modules/undici/lib/fetch/request.js:76:15)
    at new Request (/usr/local/lib/node_modules/wrangler/node_modules/@miniflare/core/src/standards/http.ts:393:13)

@pksorensen
Copy link

The actual code that is throwing is coming from reactfetch
from searching on the error in the worker.js file that get generated i found

  console.warn("React was unable to patch the fetch() function in this environment. Suspensey APIs might not work correctly as a result.");

is coming from https://github.com/facebook/react/blob/main/packages/react/src/ReactFetch.js

more specific the https://github.com/facebook/react/blob/main/packages/react/src/ReactFetch.js#L77 where new Request is used i suppect that this "Request" is different on edge runtime

@pksorensen
Copy link

related is also aws/aws-sdk-js-v3#1165

Is it that these things should be implemted in cloudflare edge runtime implmentation?

@pksorensen
Copy link

related is also sveltejs/kit#6739

Seems that running locally works but still problem on cloudflare pages

@ebifran
Copy link
Author

ebifran commented Dec 5, 2022

@pksorensen
Thank you for submitting issue on next.js!

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

Successfully merging a pull request may close this issue.

3 participants