Home > front end >  Visual Studio Code - Cannot set env without running a program (or
Visual Studio Code - Cannot set env without running a program (or

Time:04-13

I am been shown this unusual error. It has just started appearing and it's preventing me from debugging my WSL web solution.

I am running a php wordpress site in Visual Studio code and debugging it using XDebug. I have the following in my launch.json which I know for a fact worked yesterday and has been working fine for a while now.

When I try and debug I get a pop saying the following

pop up

I've never seen this message before and I can't see any information online about it.

My launch.json looks like the following

"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.

I first thought that maybe the port was being used by something elese but it wasn't.

I have tried restarting Apache2, reloading PHP7.3-fpm and turning my computer off in the hopes that the issue resolves itself yet nothing seems to be working.

Has anyone else came across this issue?

CodePudding user response:

It seems that all of a sudden, for some reason env was not recognised and VSC no longer liked it. Replacing it with enivornment (as per the comment GrafiCode suggested) in the launch.json fixed the issue.

According to @burito in the comment, env has been renamed to `environment.

My only guess as to why this happened is that I have a .env file in my root that could had of been overriding the launch and so when I launched the solution, it hit the .env file first and seen that the solution wasn't running...thereby throwing the error/ pop-up.

CodePudding user response:

php-debug dev here.

I have added this error because people don't understand that without starting a program/script the debug adapter cannot influence the environment Xdebug is running in. Effectively in your launch.json the env does nothing.

Looking back on the change, I should have introduced a warning first...

Just to clarify, env was NOT renamed to enivornment.

  • Related