2

I'm encountering a 'ReferenceError: Request is not defined' error every time I run npm start in my Node.js environment, and I suspect it's stemming from the environmental file "node_modules/@expo/server/src/environment.ts".

Here's a snippet of the environment file:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.installGlobals = exports.ExpoResponse = exports.ExpoRequest = void 0;
/* eslint-disable no-var */
const node_1 = require("@remix-run/node");
/** @deprecated */
exports.ExpoRequest = Request;
/** @deprecated */
exports.ExpoResponse = Request;
function installGlobals() {
  (0, node_1.installGlobals)();
  global.ExpoRequest = Request;
  global.ExpoResponse = Response;
}
exports.installGlobals = installGlobals;

However, I'm unsure why this error is occurring. Whenever I start Metro Bundler, it throws the error:

ReferenceError: Request is not defined at Object. (/Users/Theo/nunj/node_modules/@expo/server/src/environment.ts:23:28) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (/Users/Theo/nunj/node_modules/@expo/server/install.js:1:28) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) I would appreciate any insights or suggestions for resolving this issue. Thank you!

2
  • What version of node are you running? node --version
    – dj-doMains
    Commented May 21, 2024 at 4:20
  • @dj-doMains v16.16.0 Commented May 21, 2024 at 8:47

2 Answers 2

2

You may need to upgrade to v18 based on this change log published by Expo. https://expo.dev/changelog/2023/11-03-node-default

It highlights that node v16 reached it's end-of-life and encourages you to upgrade to v18.

I personally like to use a package called n that let's me change node versions on the fly: https://www.npmjs.com/package/n

0

I was using Node v16.x so I had to switch to 18.x and currently my 18.x is v18.19.1.

npx use 18

As per expo docs here is the default node version https://expo.dev/changelog/2023/11-03-node-default

1
  • 1
    this workd for me. if you're using nvm, give nvm use 18.18 a shot Commented Jun 3, 2024 at 9:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.