I have a tasks.json
in my VSCode that doesn't preserve the command-line environment from the dependsOn
task that has been successfully executed:
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Desktop Development Debug",
"cargo": {
"args": [
"build",
"--manifest-path=./frontend/app/src-tauri/Cargo.toml",
"--no-default-features"
]
},
// task for the `beforeDevCommand` if used, must be configured in `.vscode/tasks.json`
"preLaunchTask": "ui:dev"
},
tasks.json
:
"tasks": [
{
"label": "desktop:setup",
"type": "shell",
"command": "nvm",
"args": [
"use",
],
"isBackground": true,
"options": {
"cwd": "${workspaceFolder}/frontend/app"
}
},
{
"label": "ui:dev",
"type": "npm",
"isBackground": true,
"script": "next-dev",
"options": {
"cwd": "${workspaceFolder}/frontend/app"
},
"dependsOn": [
"desktop:setup"
]
},
Errors:
* Executing task: nvm use
Found '/path-to-project/frontend/app/.nvmrc' with version <v20.14.0>
Now using node v20.14.0 (npm v10.7.0)
* Terminal will be reused by tasks, press any key to close it.
* Executing task: npm run next-dev
> app@0.3.4 next-dev
> next dev -p 1420
You are using Node.js 16.20.2. For Next.js, Node.js version >= v18.17.0 is required.
* The terminal process "/bin/zsh '-l', '-i', '-c', 'npm run next-dev'" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
Any clue?
This was raised as a feature-request in tasks.json support to reuse the same shell #168947, but it didn't receive enough community support in time to get added to the backlog. You could try raising the feature-request again. As shown in the issue ticket, depending on context (Ex. task type
, whether the tasks share other properties, etc.), you can work around this by writing a single shell task and using shell mechanisms to do multiple commands on one commandline. Ex. bash &&
.
Also related:
options.env
property at the top level as shown in Environment variables not persisted across task chains #38793.preLaunchTask
in launch.json, see
Can preLaunchTask and launch start within the same terminal in VSCode?.