fastify / fastify-dx

Archived
901 stars 42 forks source link

globalThis.Request is not a constructor #47

Open CanRau opened 2 years ago

CanRau commented 2 years ago

Prerequisites

Fastify version

3.29.2

Plugin version

0.0.5

Node.js version

16.14.2

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

11.6.6

Description

[vite] Error when evaluating SSR module /context.ts: TypeError: globalThis.Request is not a constructor at /fastify-dx-react-ts/node_modules/ky/distribution/core/constants.js:6:26 at /fastify-dx-react-ts/node_modules/ky/distribution/core/constants.js:17:3 at ModuleJob.run (node:internal/modules/esm/module_job:197:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:337:24) at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15) at async nodeImport (/fastify-dx-react-ts/node_modules/fastify-vite/node_modules/vite/dist/node/chunks/dep-689425f3.js:724:749) at async eval (/context.ts:3:31) at async instantiateModule (/fastify-dx-react-ts/node_modules/fastify-vite/node_modules/vite/dist/node/chunks/dep-689425f3.js:722:2131)

Steps to Reproduce

Start from react-ts Install missing dependencies vite & ky run yarn build && yarn dev

Expected Behavior

Working starter

tony-go commented 2 years ago

I have the same issue, expect I didn't have to install vite & ky but history.

tony-go commented 2 years ago

I upgraded the node version to 18.x, and the issue disappeared. (Before that I was on v16.17.0 (lts))

BlackYuzia commented 2 years ago

I upgraded the node version to 18.x, and the issue disappeared. (Before that I was on v16.17.0 (lts))

So, min version for work is 18.x?

tony-go commented 2 years ago

I upgraded the node version to 18.x, and the issue disappeared. (Before that I was on v16.17.0 (lts))

So, min version for work is 18.x?

Don't know; @galvez will probably explain why, but maybe they develop with node 18 and will work on backward compat later.

tony-go commented 2 years ago

Just found this: https://github.com/es-shims/globalThis

Ky targets modern browsers and Deno. For older browsers, you will need to transpile and use a fetch polyfill and globalThis polyfill. For isomorphic needs (Node.js + browser, like SSR), check out ky-universal.

EDIT: I'll invest a bit this week to see If I can fix it myself.