skip to Main Content

I’m experiencing a weird bug whereby running npm run dev works in Terminal (shell), but it fails when executed as a VS Code task.

Here’s what the error looks like

Executing task: npm run dev 


> [email protected] dev
> next dev

/Users/bgorman/Projects/deleteme/node_modules/next/dist/server/web/spec-extension/request.js:28
class NextRequest extends Request {
                          ^

ReferenceError: Request is not defined
    at Object.<anonymous> (/Users/bgorman/Projects/deleteme/node_modules/next/dist/server/web/spec-extension/request.js:28:27)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at Module.mod.require (/Users/bgorman/Projects/deleteme/node_modules/next/dist/server/require-hook.js:64:28)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/bgorman/Projects/deleteme/node_modules/next/dist/server/web/spec-extension/adapters/next-request.js:37:18)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)

 *  Terminal will be reused by tasks, press any key to close it. 

This happens after I

  1. Create a new Next.js project with npx create-next-app@latest

  2. Create a launch.json file

    {
      "version": "0.2.0",
      "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Launch Program",
          "skipFiles": ["<node_internals>/**"],
          "program": "${file}"
        }
      ]
    }
    
  3. Create a tasks.json file

    {
      "version": "2.0.0",
      "tasks": [
        {
          "type": "npm",
          "script": "dev",
          "label": "npm: dev",
          "detail": "next dev"
        }
      ]
    }
    

Other people have reported this error and suggested upgrading node to v18,

but I’m already using node version v18.18.0. And like I said, npm run dev works fine – the error only occurs when I execute the VS Code task. (Someone else reported the same behavior here.)

Versions

  • node 18.18.0
  • npm 10.2.1
  • nvm 0.39.5
  • next 14.0.0
  • vs code 1.83.1
  • mac os 14.0

2

Answers


  1. Chosen as BEST ANSWER

    It turns out I had an old version of node installed that VS Code was using as the runtime for my tasks. Deleting the old runtime fixed it for me. Helpful post


  2. I faced same issue, Just Install Node latest version <=18.6.0

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search