When you run your Next.js application locally or when deploying it on a platform like Vercel, you may get the following error:
ReferenceError: Request is not defined
You may also get a more useful and specific error:
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.
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:
nvm install 18.17.0
You can then use the use
command to use a specific Node version:
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.
Get actionable, code-level insights to resolve Next.js performance bottlenecks and errors.
Run the line of code below to:
Create a free Sentry account
Run the CLI install command to automatically add the Sentry SDK to your project:
npx @sentry/wizard@latest -i nextjs
Start capturing errors and performance issues
Loved by over 4 million developers and more than 90,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.