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

TypeError: headers.get is not a function (vite / nightly) #7819

Closed
1 task done
ZipBrandon opened this issue Oct 30, 2023 · 3 comments
Closed
1 task done

TypeError: headers.get is not a function (vite / nightly) #7819

ZipBrandon opened this issue Oct 30, 2023 · 3 comments

Comments

@ZipBrandon
Copy link

What version of Remix are you using?

0.0.0-nightly-0c99349-20231027

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

I annotated it at the top of the repo's readme but it uses @PhilDL fork of @sergiodxa's remix-i18next to address ESM issues. sergiodxa/remix-i18next#155

  1. Clone https://github.com/ZipBrandon/remix-vite
  2. npm i
  3. npm run dev and receive the error

Expected Behavior

The route to load.

Actual Behavior

  VITE v4.5.0  ready in 716 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help

  ⚠️  Remix support for Vite is unstable
     and not recommended for production

TypeError: headers.get is not a function
    at Module.getClientLocales (/Users/lazerskates/DEVELOPMENT/forks/remix-vite/libs/remix-i18next/dist/esm/lib/get-client-locales.js:7:34)
    at LanguageDetector.fromHeader (/Users/lazerskates/DEVELOPMENT/forks/remix-vite/libs/remix-i18next/dist/esm/server.js:167:45)
    at LanguageDetector.detect (/Users/lazerskates/DEVELOPMENT/forks/remix-vite/libs/remix-i18next/dist/esm/server.js:134:37)
    at async handleRequest (/Users/lazerskates/DEVELOPMENT/forks/remix-vite/app/entry.server.tsx:29:13)
    at async handleDocumentRequestRR (/Users/lazerskates/DEVELOPMENT/forks/remix-vite/node_modules/@remix-run/server-runtime/dist/server.js:212:12)
    at async requestHandler (/Users/lazerskates/DEVELOPMENT/forks/remix-vite/node_modules/@remix-run/server-runtime/dist/server.js:93:18)
    at async /Users/lazerskates/DEVELOPMENT/forks/remix-vite/node_modules/@remix-run/dev/dist/vite/node/adapter.js:184:20
    at async /Users/lazerskates/DEVELOPMENT/forks/remix-vite/node_modules/@remix-run/dev/dist/vite/plugin.js:413:13
@hi-ogawa
Copy link
Contributor

hi-ogawa commented Nov 1, 2023

This might be due to inconsistent Request polyfills setup in vite adapter.
remix-i18next seems to use instanceof Request check in https://github.com/ZipBrandon/remix-vite/blob/33a2a42596eac88381fc8fd2b8cc3b151113c687/libs/remix-i18next/dist/esm/lib/get-client-locales.js#L29-L34, but this is probably becoming false and ended up with Request.get which is undefined.

Adding this logging to the reprodcution, this is observed:

export default async function handleRequest(
  request: Request,
  ...
) {
  console.log("### Request", Request, request.constructor);
  console.log("### request instanceof Request = ", request instanceof Request)

// ### Request [class Request extends Body] [class NodeRequest extends Request]
// ### request instanceof Request =  false

It seems vite node adapter polyfills Request global from @remix-run/node (which in turn is from @remix-run/web-fetch), but adapter is constructing a different Request instance based on undici.

import { File, FormData, Headers, Request as BaseNodeRequest } from "undici";
import { type ServerBuild, installGlobals } from "@remix-run/node";
import { createRequestHandler as createBaseRequestHandler } from "@remix-run/server-runtime";
installGlobals();


Obviously this cannot be the right solution, but adding this at least makes request get through without error...

export default async function handleRequest(
  request: Request,
  ...
) {
  (globalThis as any).Request = request.constructor

@markdalgleish
Copy link
Member

Thanks for raising this issue! This should be fixed by #8062. It will be available in the next nightly release. If you could try it and report back, that would be super helpful!

@MagnumDuck

This comment was marked as resolved.

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

No branches or pull requests

6 participants