When I run npm run dev in my nextjs project I get the following error:
.../node_modules/next/dist/server/web/spec-extension/request.js:28
class NextRequest extends Request {
^
ReferenceError: Request is not defined
at Object.<anonymous> (.../node_modules/next/dist/server/web/spec-extension/request.js:28:27)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at Module.mod.require (.../node_modules/next/dist/server/require-hook.js:64:28)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (.../node_modules/next/dist/server/web/spec-extension/adapters/next-request.js:37:18)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
Node.js v17.4.0
When I run node -v I get:
v20.9.0
I have already uninstalled node from my machine and reinstalled it using nvm.
From what I understood nextjs and the packages I have installed are complaining because I am not using the required node version. However since in my terminal when I run node -v I get that I am using v20.9 I’m not sure why else Nextjs isn’t detecting the correct node version
Anyone know how I can solve this?
2
Answers
I tried all solutions from the following discussion however none of the solutions were able to solve my problem since whenever I was running Nextjs it would still think I had an older version of Node.
I was able to solve the problem by uninstalling node and npm completly from my machine using this article. I tried to uninstall nvm but it worked without uninstalling it.
I then installed node and npm again using their official website.
Open terminal inside project and run: npm i node@lts.