How can I change the capitalization of the project directory VS Code passes when debugging? - visual-studio-code

I'm running a Next.JS project in VS Code. My launch.json has the following configuration:
{
// ...
"configurations": [
{
"name": "Frontend: Dev Server",
"request": "launch",
"runtimeArgs": [
"run-script",
"dev",
"--preserve-symlinks", // To debug linked
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"type": "node",
}
],
}
When I run this configuration from VS Code, I get an error like the following:
C:\Program Files\nodejs\npm.cmd run-script dev --preserve-symlinks
> web-client#0.1.0 dev
> next dev -p 5555
warn - Invalid casing detected for project dir, received c:\etcetc actual path C:\etcetc, see more info here https://nextjs.org/docs/messages/invalid-project-dir-casing
I know that I want VS Code to pass in the drive letter in upper case instead of lower case, but I don't see any option to set that and I tried opening the project using code C:\etcetc directly.
How can I change the capitalization of the directory that VS Code applies to the launch configuration?

Add a current working directory to your launch.json configuration:
{
// ...
"configurations": [
{
"cwd": "${workspaceFolder}",
"name": "Frontend: Dev Server",
// ...
}
]
}
This passed an upper case drive letter to Node for me. You may also want to check that VS Code is opening the folder with the right case, i.e. node C:\etcetc.
If you still have casing errors, try deleting the .next directory.

Related

VSCode Cloud Code - breakpoints are pointing unexpected file path

I am trying to debug remotely a .NET Core pod on GKE.
Everything work fine, but after starting debugging, breakpoints point different file path from the original source.
Before debugging:
Breakpoint is shown, and both its path and path of source code are same.
While debugging:
But after starts, breakpoint(red dot) disappears, and its path is changed into \src\WebApplication1\Controllers\.
My launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Kubernetes Pod (.NET Core)",
"type": "cloudcode.kubernetes",
"request": "attach",
"language": "NETCore",
"podSelector": {
"type": "webapp"
},
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
]
}

VSCode - How to specify which project to debug - Azure Functions

My question is a noobie question.
I have an azure function app project, along with a test project. Initially, I start with just the function application project and then I just recently re-org the project folders and added the associated test.csproj
The folder structure I have right now looks like this:
Since moving the function app into the "src" folder, when I want to just run locally, I make sure that from my powershell terminal, I do the following:
cd src
func start
And everything works really well. But if I want to step through the code / debug, hitting F5 doesn't work because it doesn't know which project I'm trying to debug.
Can you tell me how I can debug either project from the parent folder that I'm in ?
I've tried to change my launch.json from this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
To this:
{
"version": "0.2.0",
"configurations": [
{
"name": "FunctionApp",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}",
"program": "${workspaceFolder}/src/bin/Debug/net6.0/bin/widgets.dll",
"cwd": "${workspaceFolder}/src"
}
]
}
And now I see a Green play button with the name "FunctionApp" in my "Run and Debug" bar across the top, but when I try to run it, I get an error that says:
Executing task: C:\Program Files\dotnet\dotnet.exe clean /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Copyright
(C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1003: Specify a project or solution file. The
current working directory does not contain a project or solution file.
The terminal process "C:\Program Files\dotnet\dotnet.exe 'clean',
'/property:GenerateFullPaths=true',
'/consoleloggerparameters:NoSummary'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
EDIT 1
I tried to follow this example:
https://i.stack.imgur.com/a7ZVk.png
I also changed all references in my task.json from "process" to "shell" based on this post: Debugging Azure Function with vscode
So presently, this is what the two files look like:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
tasks.json
Just showing what I understand is the relevant section...
{
"version": "2.0.0",
"tasks": [
{
"label": "host function",
"command": "func host start",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/src"
}
},
But the error I'm getting is this:
Failed to detect running Functions host within "60" seconds. You may
want to adjust the "azureFunctions.pickProcessTimeout" setting.
When I try Run -> Start with debugging, the application starts, and I can trigger my API... but it doesn't stop at any of the breakpoints.
So the complete solution was to
a) Revert my launch.json back to the original version which looks like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
b) added new section to my tasks.json:
{
"label": "host function",
"command": "func host start",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/src"
}
},
c) Then I changed ALL references to "process" to "shell" in the tasks.json.
d) Lastly, to fix the error with azureFunctions.pickProcessTimeout, I did the following:
File -> Preferences -> Settings -> search for the specific setting and increased from 60 seconds to 180

How to debug Ember addon with breakpoints in VS Code

Am trying to get breakpoints to work in VS Code with an Ember addon (version 3.18). Have tried launch.json as:
{
"version": "0.2.0",
"configurations": [
{
"type": "edge",
"request": "launch",
"name": "Launch Edge against localhost",
"port": 9222,
"runtimeArgs": [ "--remote-debugging-port=9222" ],
"url": "http://localhost:4200",
"sourceMapPathOverrides": {
"dummy/*": "${workspaceFolder}/tests/dummy/app/*",
"test-addon/*": "${workspaceFolder}/addon/*",
}
}
]}
It works fine for setting breakpoints in files in the dummy test app. But when setting a breakpoint in files within the addon folder, VSCode says "Breakpoint set but not yet bound". How can this be fixed? I assume the 2nd sourcemap path override is wrong?
After a bit of further experimenting, seems the 2nd path should be:
"addon-tree-output/test-addon/*": "${workspaceFolder}/addon/*"
Update:
Turns out this still doesn't break inside addon files correctly. eg. in an addon component file:
#action
click() {
console.log('hello') // Set breakpoint here
}
// Instead, jumps to here
Some difference between the dummy and vendor source maps perhaps? There is an option in ember-cli-build.js:
babel: {
sourceMaps: 'inline'
}
but this only applies to the dummy test app as it states in the comment underneath it?

Debug FastAPI application in VSCode

i'm trying to debug an application (a web api) that use FastAPI (uvicorn)
I'm also using poetry and set the projev virtual environment in vscode.
i read this tutorial to setup uvicorn and this one to setup vscode but i think i'm doing something wrong in set it up.
I tried to setup the launch.json both as python: module and python: current file
The problem seems that it doesn't recognize the project structure cause when i run the debug it stopped in an import statement with this error:
Exception has occurred: ImportError
attempted relative import with no known parent package
This is my current launch.json configuration:
"configurations": [
{
"name": "Python: local debug",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/topic_service/service/__init__.py",
"args" : ["--port", "8000"]
},
]
I also tried to add a .env file setting PYTHONPATH:
PYTHONPATH=.:${PYTHONPATH}
Locally i run the application as follow:
poetry run uvicorn src.main:app --port 8080 --reload
Does anyone know how to correctly setup vscode to debug an uvicorn application?
Thank you
UPDATE:
I also tried what this article says. the debugger seems to start but nothing happen (no breakpoint is triggered)
Try this configuration.
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": ["src.main:app","--reload"]
}
Likewise you provide uvicorn module with necessary args during development of FastAPI application, you need to configure your launch.json located in .vscode directory with respective values.
I did a write up for custom project configurations to debug FastAPI in VS Code here
Suppose you issue the following command to run FastAPI on uvicorn server with args mentioned as below
uvicorn main:app --reload --port 8000
then your launch.json should have module with value of uvicorn and each of the args separated by space as items of the args array.
"module": "uvicorn",
"type": "python",
"request": "launch",
"args": [
"main:app",
"--reload",
"--port",
"8000"
],
"env": {
"usersecret": "some$Ecret",
}
You can have this launch.json file in .vscode and then modify the args array in the JSON configuration as per your project structure.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"env": {
"db_username": "postgres",
"db_password": "secret",
"host_server": "localhost",
"database_name": "fastapi",
"ssl_mode": "prefer",
"db_server_port": "5432"
},
"args": [
"main:app",
"--reload",
"--port",
"8000"
]
}
]
}
For me worked with this configurations:
On Debug section on VSCode, choose create launch.json option. Probally it will open launch.json on .vscode folder in your root folder explorer
like this, inside of launch.json put this:
"version": "0.2.0",
"configurations": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"cwd": "${workspaceFolder}/<folder to your main.py>",
"args": [
"main:app",
"--reload",
"--port", //these arg are optional
"3003"
]
}
]
}
Now , just run your debugger and have a nice day!
Edit: The cwd ensure that your debbuger will find the right path to your main.py file. So, for whos use multiple debuggers or uses outside vsCode with launch.json it's a nice choice use it.
The quick and easy way: launch debugger F5 and then select FastAPI Debug Configuration:
(p.s. this works on the VSCode Insiders; haven't tried it on a regular version)
The way i debug is quite basic, hope it helps
i have .py file with this config:
import uvicorn
from app.main import api
if __name__ == "__main__":
dev = 1
if dev==0:
#use this one
uvicorn.run(api, host="127.0.0.1", port=5000, log_level="info")
if dev == 1:
#or this one
uvicorn.run('app.main:api', host="127.0.0.1", port=5000, log_level="info", reload=True, debug=True)
if dev == 2:
uvicorn.run('app.main:api', host="127.0.0.1", port=5000, log_level="info", workers=2)
and run the file with the vscode debugger, the important thing is to run the app with the debug flag because otherwise the debugger skips the breakpoints (at least in my case)

How to start both Angular app and WebApi service from VSCode on F5 or Ctrl+F5

I have top-level folder Homepage with the following structure:
--Homepage
----Client <- Angular app, created with `ng new` command
----Server <- .NET Core WebApi, created with `dotnet new webapi` command
I open VSCode at Homepage level:
I have these extensions installed:
Question
If I want to use single VSCode environment to work on both projects, Client and Server, is it possible to bind F5 (or Ctrl+F5) to start both projects together?
Client app I start using ng serve (it will run on http port 4200)
Server app I start using dotnet run (it will run on https port 5001)
I have just one common .vscode folder on Homepage (root level):
By default, when first created, the content of launch.json was this:
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Server/bin/Debug/netcoreapp2.1/Server.dll",
"args": [],
"cwd": "${workspaceFolder}/Server",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}
So, when I press F5 it builds and start the Server app, the page opens at https://localhost:5001, from there I can navigate to https://localhost:5001/api/values and see WebApi works.
But the Client app doesn't start at all.
So, I thought if I add Debugger for Chrome extension's settings to launch.json, it should work, so I clicked on Add Configuration and added corresponding section:
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
},
I changed port from 8080 to 4200, since ng serve hosts on port 4200
But it does not start the Client app.
Please advice. Thanks
I have similar (node.js for API) and spent quite some times couldn't resolved, for example use && or &. Result is either API up or Angular up, never the both.
Anyway I finally realized have both Api and UI in the same folder/project/solution is not practical. An API is not specific to an UI, it's a universal DLL/service, should be siting somewhere by itself. So I separated them into two diff folders and have 2 VSC instances to run them:
start the API in debug mode
in 2nd VSC, run ng serve and let it take time to build
when ng says "Compiled successfully" go to launch.json to start the debug entry associated with Chrome
they work perfectly.