Sentry Answers>Next.js>

Next.js ReferenceError: Request is not defined | Reading old version of Node

Next.js ReferenceError: Request is not defined | Reading old version of Node

Matthew C.

The Problem

When you run your Next.js application locally or when deploying it on a platform like Vercel, you may get the following error:

Click to Copy
ReferenceError: Request is not defined

You may also get a more useful and specific error:

Click to Copy
You are using Node.js 16.13.1. For Next.js, Node.js version >= v18.17.0 is required.

As described in the second error message, this error is caused by not having the required Node.js version.

The Solution

Install the required Node.js version. You can use a tool like Node Version Manager (nvm) to simplify using different versions of Node on your device. nvm is a command line tool that allows you to quickly install and use different versions of Node. It allows you to use different Node versions for different projects.

To install it follow the nvm installation guide. If you use Windows, you can install nvm using WSL (Windows Subsystem for Linux). It should also work with GitBash (MSYS) or Cygwin.

Once you’ve installed nvm, you can install a specific version of Node:

Click to Copy
nvm install 18.17.0

You can then use the use command to use a specific Node version:

Click to Copy
nvm use 18.17.0

Note that you should make sure that your project dependencies work with the new Node version. This may require updating your project’s dependencies.

If you are using Vercel to deploy your Next.js application, and you have an issue with the Node.js version, you can change the Node.js version in your Vercel Dashboard Project Settings under the Node.js Version setting. By default, new projects use the latest Node.js LTS version available on Vercel.

You can define the major node version in the engines section of your project’s package.json to override the Vercel dashboard project settings.

To check which Node version your Vercel deployment is using, you can run node -v in the build command, or you can log process.version.

Make sure that the Node version in your local environment and in your deployed environment match to minimize issues caused by different Node.js versions such as dependencies having different Node.js version requirements.

  • Sentry BlogCommon Errors in Next.js and How to Resolve Them
  • Community SeriesDebug Next.js with Sentry
  • ResourcesJavaScript Frontend Error Monitoring 101
  • Syntax.fmListen to the Syntax Podcast
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Considered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

© 2024 • Sentry is a registered Trademark of Functional Software, Inc.