Debug web add-in for outlook in visual studio code - node.js

I was following the tutorial for creating an advanced Outlook add-in here (Git the Gist)
The above is a node.js-app which uses Yeoman and Microsoft Office Add-in Project Generator. To simply start the add-in, you just type 'npm start' in your root project folder.
But: I want to debug the add-in in Visual Studio Code.
VS Code automatically creates a launch.json file when you want to debug a project. This file looks like this:
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\bsconfig.json"
}
]
However, when I debug I get the following error:
Cannot launch program 'c:\ZTesting\outlooktest\bsconfig.json'; setting
the outFiles attribute might help.
So are these outFiles truly the problem and - if so - what should they be?
And - if not - what is the solution towards debugging a web add-in created with node.js, Yeoman and Microsoft Office Add-in Project Generator?
The bsconfig.json file looks like this:
{
"ui": {
"port": 3000
},
"server": {
"routes": {
"/node_modules": "node_modules"
}
},
"https": {
"key": "./certs/server.key",
"cert": "./certs/server.crt"
},
"watch": true,
"files": "*.*"
}

I did not find out how to debug the add-in above in Visual Studio Code. However it is possible to debug the add-in with the F12-developer-app from Windows 10.
You can find more information about the F12-app here:
Debug add ins using F12 Developer-app from Windows 10

I have the same problem today.
However, there is a tricky way to debug your outlook add-ins if WIN10 F12-app not able to open your html file.
you can use tbody.append to show any value when you debug your add-ins in outlook
var tbody = $('.prop-table');
tbody.append(makeTableRow("asyncResult: ", item));
function makeTableRow(name, value) {
return $("<tr><td><strong>" + name +
"</strong></td><td class=\"prop-val\"><code>" +
value + "</code></td></tr>");
}

I had this same problem. The root cause is that the app does not actually run on the server. npm start actually runs a separate program, called webpack. You can see this by opening package.json. There should be a line like the following:
"start": "webpack-dev-server --mode development --https --key ./certs/server.key --cert ./certs/server.crt --cacert ./certs/ca.crt --port 3000"
When you run npm start, it adds node_modules/.bin/ to the path before running that line. So this script is actually calling an executable called node_modules/.bin/webpack-dev-server. Webpack does not run any of the code in index.js. It "packs" the code, and broadcasts it over https to the client.
Since the app code only runs on the client, it can only be debugged on the client. The use of npm start makes it look like you're writing server code, but the add-in is actually running clientside.

Related

Node.js live debugging in VSCode doesn't work

I have a small project (but issue also appears on the one created by npx create-react-app my-app). I use VsCode and developing inside container (https://code.visualstudio.com/docs/remote/containers) . Dockerfile is very minimal:
ARG VARIANT="16-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
devcontainer.json has, almost, just defaults:
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
"args": { "VARIANT": "16-bullseye" }
},
"settings": {},
"extensions": [
"dbaeumer.vscode-eslint"
],
"remoteUser": "node"
}
To debug, I run npm start , then I (for the 1st time) i click on Debug URl.
On macOS everything works, including file monitoring, so when I change js file, npm is recompiling instantly.
On Windows 11 however, the last part doesn't work - I need to stop and start npm manually, to have changes implement.
I've even tried to remove .vscode directory from my profile - no change here...
Any idea what is going on? Why it does work on macOS and doesn't work on Windows ?
I have the same extensions on both systems...I just can't find what is going on with Windows machine...
EDIT: the issue seems to be related to "Remote Development" extension for vscode . Issue is present only when using this extension on Windows. So I've opened a bug there: https://github.com/microsoft/vscode-remote-release/issues/6633

AWS Toolkit + VSCode local testing

I'm trying to figure out how to use AWS toolkit for vscode. I go to the AWS extension and click Create New SAM Application, point to project directory and it creates a hello world function. Above it, it says Add Debug Configuration. I click that, choose nodejs 12.x and save the launch.json, but I don't get the run option. It still says Add Debug Configuration for some reason. How can I run my lambda functions locally in the console?
The launch.json file generates, but I can never run the code.
launch.json
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "new test:app.lambdaHandler (nodejs12.x)",
"invokeTarget": {
"target": "code",
"projectRoot": "new test/hello-world",
"lambdaHandler": "app.lambdaHandler"
},
"lambda": {
"runtime": "nodejs12.x",
"payload": {},
"environmentVariables": {}
}
}
]
}
I also tried navigating to the hello-world directory in terminal and executing node app.js, but it doesn't return anything
What am I doing wrong? I appreciate the help!
Make sure you have SAM CLI install in local, here are the instructions for installation https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
Then run the command sam local start-api.
You should be able to access the api at http://127.0.0.1:3000/hello
You can also do the same via vscode by selecting Run > Run without debugging (shortcut: ctrl + F5)

vscode - cannot debug express-generator project

I want to speed up development by learning to debug my programs in Visual Studio Code. I had been following the vsCode docs but ran into a snag.
I used Express (v4.16.0) to generate a plain project and added the default Node.js (v8.11.3) debug configuration to Visual Studio Code (v1.25.1)
Launching the Visual Studio Code debugger and going to the link it is listening on yields a loading blank page.
Here is a GitHub repository of the project.
When I begin debugging, vsCode prints to the debug console Debugger listening on ws://127.0.0.1:3804/123e990c-24a1-475c-beff-039206890946. I would navigate there thinking that was the new address of my project. It is not.
The address of my project is still what I specified in Express, localhost:3000. Navigating there after starting the vsCode debugger does trigger my break points and allow me to navigate my application.
sigh
{
"type": "node",
"request": "launch",
"name": "Launch",
"program": "${workspaceRoot}/bin/www"
}
change the value in program key

How can I debug a Node.js application running with PM2 in VSCode?

Visual Studio code has some awesome debug functionality built in that makes it easy to debug applications with node. However, my application is configured to use PM2. How can I set up Visual Studio Code to debug with PM2?
You can add a launch configuration in VSCode, in the file named launch.json, that attaches to the process you want like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"processId": "${command:PickProcess}"
},
{...}
]
}
Press ctrl+shift+D to show the debug section in Visual Studio Code, pick "Attach to Process" and then press "play". VSCode will automatically show you the options available on you local machine. Besides the process ids of the running node processes VSCode shows the full path of your node app so it is easy to pick the right process to attach.

How can I debug gulpfile.js when running it with Visual Studio Task Runner Explorer?

How can I debug gulpfile.js when running it with Visual Studio Task Runner Explorer? Or is there another way gulp may be launched with visual studio such that gulpfile.js may be debugged? I am aware of node-inspector but want to see if there is something native to Visual Studio.
I know that you may expect a better way of doing this but he way I currently do it is by using plain
console.log() statements inside the gulpfile.js
That way I can inspect the variables and try and spot any logic errors.
Define a .vscode\launch.json file in the folder you "Open Folder" to in VS Code with this content:
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}/src/node",
"name": "Gulp package node",
"program": "${workspaceRoot}/src/node/node_modules/gulp/bin/gulp.js",
"args": [
"package" // replace this with your gulp task name
]
}
]
}
You'll obviously want to replace the task name and the path to your code in the above.
Then you can just hit "Go" in VS Code and it will launch gulp with the debugger attached.

Resources