Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upgrade nodejs version on Azure

Currently I have Azure function and Node.js version 6.5.0 defined by default there. The goal is to upgrade it. I've checked the list of available Node.js versions on Azure, and the latest one is 8.9.4. I've read some documentation about it, where 2 ways to do it are mentioned.

1) package.json

Put the following configuration to package.json file

"engines": {
    "node": "8.9.4"
}

So I did it, but no success.

2) Application Settings

Go to Application Settings, and update the value for WEBSITE_NODE_DEFAULT_VERSION to 8.9.4

Here I have 3 issues with this method:

  • logging process.version in function shows me 6.11.0. I have no clue why...
  • In fact it's Node.js 8.9.4 there, but some ES6 features like async arrow functions throws an error
  • each time I run serverless deploy command it recreates service and resets WEBSITE_NODE_DEFAULT_VERSION value to default one, i.e. to 6.5.0

One more issue with Azure Functions: When I deploy a function with changes, Azure Portal web UI still shows me not updated function (old one), while new version of that function is running there. Weird...

Please let me know if any of you faced these issues, and maybe someone knows the reason or even solution. Thank you.

like image 487
Rashad Ibrahimov Avatar asked Jan 03 '23 13:01

Rashad Ibrahimov


2 Answers

logging process.version in function shows me 6.11.0.

As @David has said, Azure Functions runtime v1(~1) locks your node version at v6.11.

When changing WEBSITE_NODE_DEFAULT_VERSION to 8.9.4, you also need to change runtime version FUNCTIONS_EXTENSION_VERSION to beta in your application settings.

(Note that runtime switch may cause breaking changes, you can create a new function app instead if error occurs.)

And the first method using package.json doesn't work in my test.

some ES6 features like async arrow functions throws an error

After successful update of node version, async arrow functions also works fine in my test.

each time I run serverless deploy command it recreates service and resets WEBSITE_NODE_DEFAULT_VERSION value to default one

serverless deploy is a command to deploy the whole service. So it's normal to see the recreating(back to default v6.5) happen as there's no parameter for node version in your yml file.

To avoid this, use serverless deploy -f <functionname> to deploy specific function instead of the whole app.

When I deploy a function with changes, Azure Portal web ui still shows me not updated function (old one), while new version of that function is running there

Same thing happened on my side. I found script can be shown correctly in App Service Editor. But in portal and kudu, update fail to display. I also checked log files in kudu, it says Script for function 'functionname' changed. Reloading..

Have opened an issue on github about the last issue we met.

like image 117
Jerry Liu Avatar answered Jan 13 '23 05:01

Jerry Liu


Just to formalize, from my comment: Functions runtime v1 is locked down to a specific Node.js version (6.11.2 currently), per this reference document.

To use a configurable Node.js runtime, you'll, need to upgrade your Functions runtime to v2.x:

Function overview page

Function app settings, to change runtime

like image 35
David Makogon Avatar answered Jan 13 '23 05:01

David Makogon