简体   繁体   English

如何在Azure上升级nodejs版本

[英]How to upgrade nodejs version on Azure

Currently I have Azure function and Node.js version 6.5.0 defined by default there. 目前我有Azure函数和默认定义的Node.js版本6.5.0 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 . 我已经检查了Azure上可用的Node.js版本列表,最新版本是8.9.4 I've read some documentation about it, where 2 ways to do it are mentioned. 我已经阅读了一些关于它的文档 ,其中提到了两种方法。

1) package.json 1)package.json

Put the following configuration to package.json file 将以下配置放到package.json文件中

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

So I did it, but no success. 所以我做到了,但没有成功。

2) Application Settings 2)应用程序设置

Go to Application Settings, and update the value for WEBSITE_NODE_DEFAULT_VERSION to 8.9.4 转到“应用程序设置”,并将WEBSITE_NODE_DEFAULT_VERSION的值更新为8.9.4

Here I have 3 issues with this method: 这里我有3个问题:

  • logging process.version in function shows me 6.11.0 . 记录process.version函数显示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 实际上它是Node.js 8.9.4 ,但是像async arrow functions这样的ES6 async arrow functions会引发错误
  • each time I run serverless deploy command it recreates service and resets WEBSITE_NODE_DEFAULT_VERSION value to default one, ie to 6.5.0 每次运行serverless deploy命令时,它都会重新创建服务并将WEBSITE_NODE_DEFAULT_VERSION值重置为默认值,即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. Azure功能的另一个问题:当我部署带有更改的功能时,Azure门户网站UI仍然显示我没有更新功能(旧版本),而该功能的新版本正在那里运行。 Weird... 奇怪的...

Please let me know if any of you faced these issues, and maybe someone knows the reason or even solution. 如果您有任何人遇到这些问题,请告诉我,也许有人知道原因甚至是解决方案。 Thank you. 谢谢。

logging process.version in function shows me 6.11.0. 记录process.version函数显示6.11.0。

As @David has said, Azure Functions runtime v1( ~1 ) locks your node version at v6.11 . 正如@David所说,Azure Functions运行时v1( ~1 )将您的节点版本锁定在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. WEBSITE_NODE_DEFAULT_VERSION更改为8.9.4 ,还需要在应用程序设置中将运行时版本FUNCTIONS_EXTENSION_VERSION更改为beta

(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. 使用package.json的第一个方法在我的测试中不起作用。

some ES6 features like async arrow functions throws an error 某些ES6功能(如异步箭头功能)会引发错误

After successful update of node version, async arrow functions also works fine in my test. 成功更新节点版本后, async arrow functions在我的测试中也能正常工作。

each time I run serverless deploy command it recreates service and resets WEBSITE_NODE_DEFAULT_VERSION value to default one 每次运行无服务器部署命令时,它都会重新创建服务并将WEBSITE_NODE_DEFAULT_VERSION值重置为默认值

serverless deploy is a command to deploy the whole service. serverless deploy是部署整个服务的命令。 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. 因此,在yml文件中没有节点版本的参数时,会发现重新创建(返回到默认值v6.5)是正常的。

To avoid this, use serverless deploy -f <functionname> to deploy specific function instead of the whole app. 为避免这种情况,请使用serverless deploy -f <functionname>来部署特定功能而不是整个应用程序。

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 当我部署带有更改的功能时,Azure门户网站ui仍然显示我没有更新功能(旧版本),而该功能的新版本在那里运行

Same thing happened on my side. 同样的事情发生在我身边。 I found script can be shown correctly in App Service Editor. 我发现脚本可以在App Service Editor中正确显示。 But in portal and kudu, update fail to display. 但在portal和kudu中,更新无法显示。 I also checked log files in kudu, it says Script for function 'functionname' changed. Reloading. 我还检查了kudu中的日志文件,它说Script for function 'functionname' changed. Reloading. Script for function 'functionname' changed. Reloading. .

Have opened an issue on github about the last issue we met. 已经打开了一个问题,关于我们见面的最后一个问题github上。

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 . 只是为了形式化,从我的评论:根据这个参考文档 ,函数运行时v1被锁定到特定的Node.js版本(当前为6.11.2)。

To use a configurable Node.js runtime, you'll, need to upgrade your Functions runtime to v2.x: 要使用可配置的Node.js运行时,您需要将Functions运行时升级到v2.x:

功能概述页面

功能应用设置,用于更改运行时

You can set the WEBSITE_NODE_DEFAULT_VERSION By checking the nodejs version from D://program files(x86)/nodejs. 您可以通过从D://程序文件(x86)/ nodejs检查nodejs版本来设置WEBSITE_NODE_DEFAULT_VERSION It will list up with all available versions. 它将列出所有可用版本。 Choose one and update WEBSITE_NODE_DEFAULT_VERSION 选择一个并更新WEBSITE_NODE_DEFAULT_VERSION

This worked for me. 这对我有用。 I have changed 8.11 to 8.11.1 我已将8.11更改为8.11.1

Go to your App directory you will see iisnode.yml. 转到您的App目录,您将看到iisnode.yml。 Make sure that node.js version correctly specified there also. 确保还在那里正确指定了node.js版本。 There should be something like this: 应该是这样的:

nodeProcessCommandLine: some_dir\\nodejs\\8.9.4\\node.exe

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM