Azure Functions local HTTP trigger issue and solution - node.js

Just wanted to post the steps I took after running into the following error when trying to run an Azure Function HTTP Trigger locally in VS Code:
"[error] Incompatible Node.js version. The version you are using is v13.1.0,
but the runtime requires an LTS-covered major version. LTS-covered versions
have an even major version number (8.x, 10.x, etc.) as per
https://github.com/nodejs/Release#release-plan. For deployed code, change
WEBSITENODEDEFAULT_VERSION to '~10' in App Settings. Locally, install or
switch to a supported node version (make sure to quit and restart your code
editor to pick up the changes)."

(1.) install NVM. Instructions here: https://github.com/nvm-sh/nvm#installing-and-updating
(2.) install NVS. Instructions here: https://github.com/jasongin/nvs
(3.) in your VS code terminal, run:
nvs add 12.16.1
nvs use node/12.16.1/x64
(4.) edit your launch.json to the following:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Node Functions",
"type": "node",
"request": "attach",
"port": 5555,
"preLaunchTask": "func: host start"
}
],
"node": {
"runtimeVersion": "12.16.1"
}
}
(5.) in your VS code terminal, run:
func start

Related

Firebase emulator --inspect-functions throws unsupported warning

Somehow i managed to break something with my firebase emulator. It already worked in the past and i don´t know why its no longer working.
When calling
firebase emulators:start --inspect-functions
Everythings starts up as expected, but i get the warning
--inspect-functions only supported for Node.js runtimes.
When trying to attach the debugger in VS Code its visible in the CALL STACK for ~5 seconds an then disappears.
Also in the terminal i don´t get the "Debugger attached" message when starting.
Here is my launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Debug",
"restart": true,
"port": 9229
}
]
}
Does anyone have a idea why its not working?
As per the discussion from this githud thread , Issue must be with firebase-tools version. Downgrading to an older version (i.e v11.21.0) of firebase-tools will solve the issue.

VS Code + Node Launch + Run Time Args

Currently attempting to setup VS Code to run a node app, however, unable to get it to work correctly. I can run it however manually without an issue. With the goal once it's running to be able to attach to the node process for breakpoint debugging:
Manual operation that works:
navigate to the directory: /Users/me/source/app_modules/main-api/
run nvm use 12 to be using v12.22.1
run node -r esm dev-server.js
Runs correctly, and loads the esm package module so imports work correctly.
When running with launch.json:
{
"version": "0.2.0",
"configurations": [
{
"envFile": "${workspaceFolder}/app_modules/main-api/.env.local",
"type": "node",
"request": "launch",
"name": "Launch API",
"cwd": "${workspaceFolder}/app_modules/main-api/",
"runtimeVersion": "12",
"runtimeArgs": ["-r esm"],
"program": "${workspaceFolder}/app_modules/main-api/dev-server.js",
}
]
}
Running with this results in: /Users/me/.nvm/versions/node/v12.22.12/bin/node: bad option: -r esm
It's not finding the node_modules even though I request it to use the main-api directory as the main working directory.

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)

Visual studio code Debugger not getting attached with sample express project generated by express generator

Node js Version :v8.11.3
VS Code version :1.29.1 x64
npm version :6.6.0
Hi ,
I have created a default express skeleton project using express --view=jade myapp command after that cd myapp/ and npm install in the last.
Now I am trying to attach vscode debugger to this newly created project but no luck.
This is the content of my launch.json
{
// 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": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"protocol":"inspector",
"port":3000,
"program": "/home/pankaj/myfirstapp/myapp/app.js"
}
]
}
I am also not able to see any error in the debug console .There is nothing in debug console neither success nor failure.
Thanks In advance
Be careful for express default setup to set the path of program in launch.json to "program": "${workspaceFolder}/bin/www"
Port 3000 is the application port of your express application. If you specify this in your launch configuration, the VS Code debugger will try to use it as the debug port (which obviously cannot work).
In addition, use VS Code variables to specify where your programs lives. E.g. if you have opened VS Code on your myapp directory, use ${workspaceFolder}/app.js for the program attribute:
E.g.:
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app.js"
}

How take out "Warning: This is an experimental feature and could change at any time" message

Basically, I have followed
VSCode: Is it possible to supress experimental decorator warnings in order to take such message out but no effect has been produced.
Firstly, I was receiving this message:
"(node:15077) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead". I read somewhere to add "protocol": "auto" in launch.json (honestly, I have no idea what I have setup to automatic).
It changed the warning mentioned in this topic. Well, I have added jsconfig.json to the project root but it seems not change anything.
I don't know if it is relevant but I noted that Visual Studio Code About points to Node 6.5.0 while my local Node is 7.7.4.
At last, but not least, what does such warning mean?
launch.json
{
// 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",
"name": "Launch Program",
"program": "${workspaceRoot}/server.js",
"protocol": "auto"
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"address": "localhost",
"port": 5858
}
]
}
jsconfig.json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "amd",
"target": "ES6"
},
"files": []
}
Debian shell
demetrio#nodejs ~/tool/elasticsearch-head $ node -v
v7.7.4
Visual Studio Code About:
Version 1.10.2
Commit 8076a19fdcab7e1fc1707952d652f0bb6c6db331
Date 2017-03-08T14:00:46.854Z
Shell 1.4.6
Renderer 53.0.2785.143
Node 6.5.0
Setting the protocol in the launch configuration is telling visual studio code which debugger to use.
The original debugger can be specified using:
'protocol': 'legacy'
The newer debugger can be specified using:
'protocol': 'inspector'
And finally the option:
'protocol': 'auto'
allows visual studio code to decided which debugger to use. It looks like with the Feb release of code (1.10) it used the newer one for node versions >=6.9. For the March release of code (1.11) it uses the newer one only for node versions 8.x.
See the following links for more information about the two different debuggers:
Feb 1.10 release
March 1.11 release
It is the newer debugger which is causing this message. Either specify you want the legacy debugger, or upgrade your code to version 1.11 (and use node < v8) to remove it.

Resources