首页 > 解决方案 > Azure NodeJS 版本

问题描述

好吧我放弃了。为什么 Azure 有一些默认版本的节点(0.10.x 为 gawds 缘故)然后依赖于使用硬编码路径来获取所需的特定版本?那不是我的问题(这是修辞)。

这种安排的问题在于,似乎对节点进行了“内部”(对应用程序)调用,当然使用了 $PATH 中的调用。

我们有一个 nodejs、express、angular 应用程序。

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

我必须通过对已安装的节点模块进行硬编码引用来将调用移入gulpng移出 Azure 。包含deploy.shdeploy.sh

#!/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 生产构建的一部分,是一个模拟步骤。它似乎有一个“内部节点调用”并且失败了:

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 似乎要求您执行的完整路径):

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.!(这个改变实际上并没有奏效,所以我恢复了)。

有谁知道为什么要设置绑定Node 0.10.x以及可以做些什么来防止这个问题?

标签: node.jsangularazure

解决方案


有一个Node versioning用于 Azure WebApps 的 Project Kudu 的 wiki 页面可以回答您关于 Node 版本的问题。2017 年 10 月 31 日之前编辑 wiki 页面时,默认节点版本为v0.6.20,现在为0.10.40。这似乎取决于 Azure WebApps 的部署模板。

创建 webapp 后,您可以在 Azure 门户的选项卡中配置 Azure Website 环境变量 WEBSITE_NODE_DEFAULT_VERSION的值来更改默认的 Node 版本Application settings,如下图,就像Change the Node versionwiki 页面的小节Configurable settings所说。

在此处输入图像描述

关于 Azure WebApps 中所有可用的 Node 版本,您可以在Kudu 控制台ls路径下命令,如下图所示。D:\Program Files (x86)\nodejs

在此处输入图像描述

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

在此处输入图像描述

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


推荐阅读