next.js: class NextRequest extends Request { ^ ReferenceError: Request is not defined

Link to the code that reproduces this issue

https://github.com/adarsh-drishya/next-turbo-bug

To Reproduce

  1. npm i
  2. npm run dev

Current vs. Expected behavior

class NextRequest extends Request {
                          ^

ReferenceError: Request is not defined

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows Server 2019 Datacenter
Binaries:
  Node: 16.16.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 13.5.7-canary.14
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

Breaking to even start the local host in npm run dev or even npm run dev-turbo

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Reactions: 16
  • Comments: 28 (3 by maintainers)

Most upvoted comments

This is expected based on your reproduction. The latest canary requires Node.js 18, but you seem to be on 16. See https://github.com/vercel/next.js/blob/f154bb831358985b69db83e6da276db24d795718/packages/next/package.json#L320

For context: Next.js stopped polyfilling fetch in favor of the platform-provided implementation, which is present in Node.js 18+ releases.

Also not that Node.js has reached end of life, so it’s good to upgrade anyway.

Thanks you guys, I had the same problem

Open terminal inside project and run: npm i node@lts This helped me.

It is working with both 18.17 and 20.9.0 for me. All I had to do was just run npm or yarn install in the same terminal where I changed the node version and then run npm run dev or yarn dev using that terminal only. Or you should make node 18.17 or 20 default node version and then try installing and run dev command

@HovhannesMkoyan I’m experiencing the same thing. npm run dev works but my script fails. For reference, my scripts look like this

{
  "name": "myapp",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
...
}

(In case it wasn’t clear, the same script worked fine before I upgraded next to 14.0.0)


Update

My problem turned out to be an old version of node installed on my machine that I wasn’t aware of, which VS Code was using whenever I ran a node task. Discussed this more here.

I have node v20 as my global default version, and whenever/wherever I check for the version it’s always 20.9.0. What’s interesting is that explicitly running npm run dev in the terminal actually starts the server, however, when trying to run this script from the Visual Studio Code npm scripts section, it gives the error above. I tried to restart both my Visual Studio Code and my Mac, but still getting the issue above when using the script.

@LucasSlepetys yeah, running the following 3 commands solved the issue for me:

rm -rf /usr/local/bin/npm rm -rf /usr/local/bin/node nvm use default

I have node v20 as my global default version, and whenever/wherever I check for the version it’s always 20.9.0. What’s interesting is that explicitly running npm run dev in the terminal actually starts the server, however, when trying to run this script from the Visual Studio Code npm scripts section, it gives the error above. I tried to restart both my Visual Studio Code and my Mac, but still getting the issue above when using the script.

I am facing the exactly same issue. Have you been able to solve it?

@balazsorban44 I’m using node v20.9.0 but still getting the same issue. Does the major have to be 18?

@PeterGKafkakis, maybe you are using V17 as the default version for VS code. Try running nvm use v20.9.0 and restart the app.

Thank you!

I wasn’t able to fix it by just running these commands, however I was able to solve the problem by uninstalling node and npm completly from my machine using this article.

I then installed node and npm again using their website.

run nvm install --lts

This is expected based on your reproduction. The latest canary requires Node.js 18, but you seem to be on 16. See

https://github.com/vercel/next.js/blob/f154bb831358985b69db83e6da276db24d795718/packages/next/package.json#L320

For context: Next.js stopped polyfilling fetch in favor of the platform-provided implementation, which is present in Node.js 18+ releases.

Also not that Node.js has reached end of life, so it’s good to upgrade anyway.

A warning would be greatly appreciated when either 1) the error pop ups or 2) setting up next.js.

I understand that 16 has reached end of life but having a very vague error that doesn’t point you in any direction is a pretty rough DX. Next 14 is now on stable and the setup command pulls from there so a little bit more verbose error handling would be appreciated.