Home  >  Q&A  >  body text

Visual Studio Code - Can't set environment variables without executing the program

I saw this unusual error. It just started appearing and preventing me from debugging my WSL web solution.

I'm running a PHP WordPress site in Visual Studio Code and debugging it using XDebug. I have the following in my launch.json, I know it worked yesterday and has been working for a while.

When I try to debug, I get a popup message that says the following

I have never seen this message before and can't see anything about it online.

My launch.json looks like below

"version": "0.2.0",
"configurations": [
    {
        "name":"Listen for XDebug",
        "type":"php",
        "request":"launch",
        "port":9003,
        "pathMappings": {
            "server path": "${workspaceRoot}" 
        },
        "xdebugSettings": {
            "max_data": 10000,
            //"show_hidden": 1,
            "max_children": 250,
            "max_depth": 10
        },
        "env": {
            "XDEBUG_MODE": "debug",
            "XDEBUG_TRIGGER": "VSCODE"
        }
    }
]

'Server path' is the path of the project on the server.

My first thought was that the port might be used by something else, but that's not the case.

I've tried restarting Apache2, reloading PHP7.3-fpm, and shutting down the computer in hopes that the problem would resolve itself, but nothing seems to work.

Has anyone else encountered this problem?

P粉447785031P粉447785031230 days ago342

reply all(2)I'll reply

  • P粉333395496
  • P粉798343415

    P粉7983434152024-03-27 10:16:26

    It seems that all of a sudden, for some reason env is not recognized and VSC doesn't like it anymore. Replacing it with enivornment in launch.json (as per GrafiCode suggested comment) fixed the issue.

    Per @burito in the comments, env has been renamed to `environment.

    My only guess as to why this is happening is that I have a .env file in my root directory that may be overriding the startup, so when I launch the solution it encounters Going to the .env file first revealed that the solution was not running...thus throwing errors/popups.

    reply
    0
  • Cancelreply