Azure NodeJS版本 [英] Azure NodeJS version

查看:122
本文介绍了Azure NodeJS版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我放弃.为什么Azure具有某个默认版本的节点(出于安全考虑,为0.10.x),然后依赖于对所需的特定版本使用硬编码路径?那不是我的问题(这是夸夸其谈).

Ok I give up. Why does Azure have some default version of node (0.10.x for gawds sake) and then relies on using hard-coded paths for the specific version required? That was not my question (it was rhetorical).

这种安排的问题在于,似乎对节点进行了内部"(对应用程序)调用,并且当然使用了$ PATH中的那个.

The problem with this arrangement is that it seems that "internal" (to the app) calls are made to node and of course the one in $PATH is used.

我们有一个nodejs,express,Angular应用程序.

We have an nodejs, express, angular app.

我的第一个问题(尽管不是本文的原因)是我在/, angular/ and server/目录中嵌套了package.json文件.根目录一号调用安装在子目录上.这在Azure中不起作用.

My first problem (though not the causes for this post) was that I have nested package.json files in /, angular/ and server/ directories. The root one calls install on the sub-directories. This does not work in Azure.

我必须通过对已安装的节点模块进行硬编码引用,将对gulpng的调用移至Azure deploy.sh. deploy.sh包含:

I had to move the calls to gulp and ng out to the Azure deploy.sh by making hard-coded references to the installed node modules. The deploy.sh contains:

#!/bin/bash

...
NODE_EXE=`cat "$DEPLOYMENT_TEMP/__nodeVersion.tmp"`
NPM_CMD="\"$NODE_EXE\" \"$NPM_JS_PATH\""
GRUNT_CMD="\"$NODE_EXE\" ./node_modules/gulp/bin/gulp.js"
NG_CMD="\"$NODE_EXE\" ./node_modules/@angular/cli/bin/ng"

...

cd server
eval $NPM_CMD install --production
eval $GRUNT_CMD build

cd ../angular
eval $NPM_CMD install --production
eval $NG_CMD build --prod

cd ..

作为NG生产的一部分,这是一个简化步骤.它似乎有一个内部节点调用",但失败了:

As part of the NG production build is a mimification step. It appears to have an 'internal node call' and is failing:

remote: Selected node.js version 10.14.1. Use package.json file to choose a different version.
remote: Selected npm version 6.4.1
...
...
...
remote: Date: 2019-01-04T04:20:42.367Z
remote: ERROR in ./src/styles.scss
remote: Hash: 8062ccafe553f9f5894b
remote: Time: 33752ms
remote: chunk {0} runtime.ec2944dd8b20ec099bf3.js (runtime) 1.41 kB [entry] [rendered]
remote: chunk {1} main.9868d9b237c3a48c54da.js (main) 128 bytes [initial] [rendered]
remote: chunk {2} polyfills.85f47f0bf59079cbc23a.js (polyfills) 130 bytes [initial] [rendered]
remote: chunk {3}  (styles) [initial] [rendered]
remote: An error has occurred during web site deployment.
remote: Module build failed (from D:/home/site/wwwroot/angular/node_modules/mini-css-extract-plugin/dist/loader.js):
remote: ng build in angular failed
remote: ModuleBuildError: Module build failed (from D:/home/site/wwwroot/angular/node_modules/sass-loader/lib/loader.js):
remote: Error: Missing binding D:\home\site\wwwroot\angular\node_modules\node-sass\vendor\win32-ia32-64\binding.node
remote: Node Sass could not find a binding for your current environment: Windows 32-bit with Node.js 10.x
remote:
remote: Found bindings for the following environments:
remote:   - Windows 32-bit with Node 0.10.x

./src/styles.scss包含:

@import '~@dhsui/kit/styles/dhs-kit-all';
@import "~bootstrap/dist/css/bootstrap.css";

我尝试进行更改以将所需版本的节点目录添加到PATH(并更改为仅调用node而不是Azure似乎要求您执行的完整路径):

I tried making a change to prepend the desired version of node directory to the PATH (and changed to just calling node rather than the full path that Azure seems to require you to do):

NODE_DIR=$(dirname "$(echo $NODE_EXE | tr '\\' '/')" | tr '/' '\\')
export PATH=$NODE_DIR:$PATH

但是它在同一个地方失败了.因此,看来我的问题不是that "internal" (to the app) calls are made to node and of course the one in $PATH is used.! (此更改实际上没有用,所以我还原了.)

But it failed at the same place. So it seems my problem is not that "internal" (to the app) calls are made to node and of course the one in $PATH is used.! (This change actually didn't work so I reverted).

有人知道为什么要为Node 0.10.x设置绑定吗?如何防止此问题发生?

Does anyone know why the binding has been setup for Node 0.10.x and what can be done to prevent this problem?

推荐答案

有一个Wiki页面

There is a wiki page Node versioning of Project Kudu for Azure WebApps which can answer your question about Node version. Before Oct 31, 2017 when the wiki page be edited, the default node version is v0.6.20, now it is 0.10.40. It seems to be up to the deployment template of Azure WebApps.

创建Webapp后,您可以配置Azure的值

After your webapp was created, you can configure the value of Azure Website environment variable WEBSITE_NODE_DEFAULT_VERSION to change the default Node version in the tab Application settings of Azure portal, as the figure below, like the subsection Change the Node version of the wiki page Configurable settings said.

关于Azure WebApp中所有可用的节点版本,您可以在Kudu控制台的路径D:\Program Files (x86)\nodejs下命令ls将其列出,如下图所示.

About the all available Node versions in Azure WebApps, you can command ls under the path D:\Program Files (x86)\nodejs of Kudu console to list them as the figure below.

设置WEBSITE_NODE_DEFAULT_VERSION后,您的网站将自动重新启动并且Node版本已升级.

After you set the WEBSITE_NODE_DEFAULT_VERSION, your website will autorestart and the Node version has been upgraded.

然后,您可以使脚本直接在当前的Node版本上运行,而无需考虑这些环境变量,例如PATH或其他有关Node的变量.

Then you can make your script works directly on the current Node version, without considering for these environment variables like PATH or others about Node.

这篇关于Azure NodeJS版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆