Kudu: Kudu fails to select npm version when node version is 10.16.3

Created on 11 Oct 2019  路  7Comments  路  Source: projectkudu/kudu

Error logs summary

{{YESTERDAY'S WORKING PART
2019-10-09T13:09:16.061Z - Resolved to version 10.1.0
2019-10-09T13:09:16.092Z - Detecting npm version spec...
2019-10-09T13:09:16.127Z - Using default for node 10.1.0: 6.0.1
-------------------------------------------
TODAY'S PART
2019-10-11T07:34:34.305Z - Resolved to version 10.16.3
2019-10-11T07:34:34.338Z - Detecting npm version spec...
2019-10-11T07:34:34.364Z - An error has occurred during web site deployment.
2019-10-11T07:34:34.388Z - select node version failed}}

I was using this deploy.sh to deploy my node.js application everyday. Today it didn't work and it threw an error when selecting node version.

deploy.sh

#!/bin/bash

# ----------------------
# KUDU Deployment Script
# Version: 1.0.9
# ----------------------

# Helpers
# -------

exitWithMessageOnError () {
  if [ ! $? -eq 0 ]; then
    echo "An error has occurred during web site deployment."
    echo $1
    exit 1
  fi
}

# Prerequisites
# -------------

# Verify node.js installed
hash node 2>/dev/null
exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment."

# Setup
# -----

SCRIPT_DIR="${BASH_SOURCE[0]%\\*}"
SCRIPT_DIR="${SCRIPT_DIR%/*}"
ARTIFACTS=$SCRIPT_DIR/../artifacts
KUDU_SYNC_CMD=${KUDU_SYNC_CMD//\"}

if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then
  DEPLOYMENT_SOURCE=$SCRIPT_DIR
fi

if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then
  NEXT_MANIFEST_PATH=$ARTIFACTS/manifest

  if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then
    PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH
  fi
fi

if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then
  DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot
else
  KUDU_SERVICE=true
fi

if [[ ! -n "$KUDU_SYNC_CMD" ]]; then
  # Install kudu sync
  echo Installing Kudu Sync
  npm install kudusync -g --silent
  exitWithMessageOnError "npm failed"

  if [[ ! -n "$KUDU_SERVICE" ]]; then
    # In case we are running locally this is the correct location of kuduSync
    KUDU_SYNC_CMD=kuduSync
  else
    # In case we are running on kudu service this is the correct location of kuduSync
    KUDU_SYNC_CMD=$APPDATA/npm/node_modules/kuduSync/bin/kuduSync
  fi
fi

# Node Helpers
# ------------

selectNodeVersion () {
  if [[ -n "$KUDU_SELECT_NODE_VERSION_CMD" ]]; then
    SELECT_NODE_VERSION="$KUDU_SELECT_NODE_VERSION_CMD \"$DEPLOYMENT_SOURCE\" \"$DEPLOYMENT_TARGET\" \"$DEPLOYMENT_TEMP\""
    eval $SELECT_NODE_VERSION
    exitWithMessageOnError "select node version failed"

    if [[ -e "$DEPLOYMENT_TEMP/__nodeVersion.tmp" ]]; then
      NODE_EXE=`cat "$DEPLOYMENT_TEMP/__nodeVersion.tmp"`
      exitWithMessageOnError "getting node version failed"
    fi

    if [[ -e "$DEPLOYMENT_TEMP/__npmVersion.tmp" ]]; then
      NPM_JS_PATH=`cat "$DEPLOYMENT_TEMP/__npmVersion.tmp"`
      exitWithMessageOnError "getting npm version failed"
    fi

    if [[ ! -n "$NODE_EXE" ]]; then
      NODE_EXE=node
    fi

    NPM_CMD="\"$NODE_EXE\" \"$NPM_JS_PATH\""
  else
    NPM_CMD=npm
    NODE_EXE=node
  fi
}

##################################################################################################################################
# Deployment
# ----------

echo Handling node.js deployment.
# 1. Select node version
selectNodeVersion

# 2. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
  "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
  exitWithMessageOnError "Kudu Sync failed"
fi



##################################################################################################################################
echo "Finished successfully."

deployment logs

2019-10-11T07:34:22.899Z - Updating branch '0ba0b32825bc3ff30da5266bdfe2deea4887dd88'.
2019-10-11T07:34:31.820Z - Updating submodules.
2019-10-11T07:34:31.940Z - Preparing deployment for commit id '0ba0b32825'.
2019-10-11T07:34:32.438Z - Running custom deployment command...
2019-10-11T07:34:32.549Z - Not setting execute permissions for bash deploy.sh
2019-10-11T07:34:32.658Z - Running deployment command...
2019-10-11T07:34:32.681Z - Command: bash deploy.sh
2019-10-11T07:34:33.106Z - Handling node.js deployment.
2019-10-11T07:34:34.131Z - Detecting node version spec...
2019-10-11T07:34:34.176Z - ENOENT: no such file or directory, open '/opt/nodejs/10.16.3/npm.txt'
2019-10-11T07:34:34.244Z - Using appsetting WEBSITE_NODE_DEFAULT_VERSION value: 10
2019-10-11T07:34:34.280Z - Node.js versions available on the platform are: 4.4.7, 4.5.0, 4.8.0, 6.2.2, 6.6.0, 6.9.3, 6.10.3, 6.11.0, 6.17.1, 8.0.0, 8.1.4, 8.2.1, 8.8.1, 8.9.4, 8.11.2, 8.12.0, 8.15.1, 8.16.1, 9.4.0, 10.1.0, 10.10.0, 10.14.2, 10.16.3, 12.9.1.
2019-10-11T07:34:34.305Z - Resolved to version 10.16.3
2019-10-11T07:34:34.338Z - Detecting npm version spec...
2019-10-11T07:34:34.364Z - An error has occurred during web site deployment.
2019-10-11T07:34:34.388Z - select node version failed
2019-10-11T07:34:34.480Z - ENOENT: no such file or directory, open '/opt/nodejs/10.16.3/npm.txt'\n/opt/Kudu/Scripts/starter.sh bash deploy.sh
2019-10-11T07:34:35.483Z - App container will begin restart within 10 seconds.

yesterday's working deployment logs

2019-10-09T13:09:11.264Z - Updating submodules.
2019-10-09T13:09:11.864Z - Preparing deployment for commit id '9d26663ea3'.
2019-10-09T13:09:12.527Z - Running custom deployment command...
2019-10-09T13:09:12.680Z - Not setting execute permissions for bash deploy.sh
2019-10-09T13:09:12.881Z - Running deployment command...
2019-10-09T13:09:12.912Z - Command: bash deploy.sh
2019-10-09T13:09:15.099Z - Handling node.js deployment.
2019-10-09T13:09:15.593Z - Detecting node version spec...
2019-10-09T13:09:15.624Z - Using appsetting WEBSITE_NODE_DEFAULT_VERSION value: 10
2019-10-09T13:09:16.020Z - Node.js versions available on the platform are: 4.4.7, 4.5.0, 6.2.2, 6.6.0, 6.9.3, 6.10.3, 6.11.0, 8.0.0, 8.1.0, 8.2.1, 8.8.1, 8.9.4, 8.11.2, 9.4.0, 10.1.0.
2019-10-09T13:09:16.061Z - Resolved to version 10.1.0
2019-10-09T13:09:16.092Z - Detecting npm version spec...
2019-10-09T13:09:16.127Z - Using default for node 10.1.0: 6.0.1
2019-10-09T13:09:16.274Z - NPM versions available on the platform are: 2.15.8, 2.15.9, 3.9.5, 3.10.3, 3.10.10, 5.0.3, 5.4.2, 5.6.0, 6.0.1.
2019-10-09T13:09:16.316Z - Resolved to version 6.0.1
2019-10-09T13:09:16.937Z - Kudu sync from: '/home/site/repository' to: '/home/site/wwwroot'
...

Project structure

package.json
server.js
deploy.sh
.deployment
web.config

I appreciate any help. What would be possible workaround?

Most helpful comment

Well, I've been working with @pesimeao on this issue and the temporary workaround is to set the NPM_CMD to a fixed version (10.14., in our case) in the deploy.sh script and disable the Node version selection (selectNodeVersion) by commenting that line. Our deploy.sh look like this

# Deployment
# ----------

## Force NPM Version
NPM_CMD="node /opt/nodejs/10.14.2/bin/npm"

# 1. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
  "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
  exitWithMessageOnError "Kudu Sync failed"
fi

# disable selectNodeVersion
# 2. Select node version
# selectNodeVersion

This link pointed out to the workaround.

Related to this.

All 7 comments

deleting .deployment and deploy.sh files solved my problem. It started to use some default oryx build thing.

Hi @nb256 , I'm facing the same problem to deploy to Azure.
I've tried to remove both .deployment and deploy.sh files but this is still giving errors.
Can you provide your last log?

2019-12-18T15:42:04  Fetching changes.
2019-12-18T15:42:04    Cleaning up temp folders from previous zip deployments and extracting pushed zip file /tmp/zipdeploy/d027c7b6-fc27-4af6-b5b3-879a26f49852.zip (45.90 MB) to /tmp/zipdeploy/extracted
2019-12-18T15:42:08  Updating submodules.
2019-12-18T15:42:08  Preparing deployment for commit id '0663cdb236'.
2019-12-18T15:42:08  Generating deployment script.
2019-12-18T15:42:08    Using the following command to generate deployment script: 'azure site deploymentscript -y --no-dot-deployment -r "/tmp/zipdeploy/extracted" -o "/home/site/deployments/tools" --node'.
2019-12-18T15:42:11    Generating deployment script for node.js Web Site
2019-12-18T15:42:11    Generated deployment script files
2019-12-18T15:42:12  Running deployment command...
2019-12-18T15:42:12    Command: "/home/site/deployments/tools/deploy.sh"
2019-12-18T15:42:12    Handling node.js deployment.
2019-12-18T15:42:12    Kudu sync from: '/tmp/zipdeploy/extracted' to: '/home/site/wwwroot'
2019-12-18T15:42:12    Copying file: 'npm-shrinkwrap.json'
2019-12-18T15:42:13    Detecting node version spec...
2019-12-18T15:42:14    Using appsetting WEBSITE_NODE_DEFAULT_VERSION value: 10.1
2019-12-18T15:42:14    ENOENT: no such file or directory, open '/opt/nodejs/10.1.0/npm.txt'
2019-12-18T15:42:14    Node.js versions available on the platform are: 4.4.7, 4.5.0, 4.8.0, 6.2.2, 6.6.0, 6.9.3, 6.10.3, 6.11.0, 6.17.1, 8.0.0, 8.1.4, 8.2.1, 8.8.1, 8.9.4, 8.11.2, 8.12.0, 8.15.1, 8.16.2, 9.4.0, 10.1.0, 10.10.0, 10.14.2, 10.17.0, 12.13.0.
2019-12-18T15:42:14    Resolved to version 10.1.0
2019-12-18T15:42:14    Detecting npm version spec...
2019-12-18T15:42:14    An error has occurred during web site deployment.
2019-12-18T15:42:14    select node version failed
2019-12-18T15:42:14    ENOENT: no such file or directory, open '/opt/nodejs/10.1.0/npm.txt'
/opt/Kudu/Scripts/starter.sh "/home/site/deployments/tools/deploy.sh"
2019-12-18T15:42:14  

trying different versions of nodejs through appsetting 'WEBSITE_NODE_DEFAULT_VERSION' may help... I removed all the custom deployment scripts and it worked.

I use '10' for WEBSITE_NODE_DEFAULT_VERSION, maybe node 10.1 is problematic.

I hope it helps.

I've tried most of them starting on 10 and none works.
However, setting 10-lts and 12-lts seems to work - kudu script fails to choose a node version and fallback to the current one, that works.

2019-12-18T17:01:34  Fetching changes.
2019-12-18T17:01:34    Cleaning up temp folders from previous zip deployments and extracting pushed zip file /tmp/zipdeploy/b29851eb-e52f-4aec-b4c0-0b1a17002abd.zip (0.00 MB) to /tmp/zipdeploy/extracted
2019-12-18T17:01:34  Updating submodules.
2019-12-18T17:01:35  Preparing deployment for commit id '3c0bd49b31'.
2019-12-18T17:01:35  Generating deployment script.
2019-12-18T17:01:35    Using cached version of deployment script (command: 'azure -y --no-dot-deployment -r "/tmp/zipdeploy/extracted" -o "/home/site/deployments/tools" --node').
2019-12-18T17:01:35  Running deployment command...
2019-12-18T17:01:36    Command: "/home/site/deployments/tools/deploy.sh"
2019-12-18T17:01:36    Handling node.js deployment.
2019-12-18T17:01:36    Kudu sync from: '/tmp/zipdeploy/extracted' to: '/home/site/wwwroot'
2019-12-18T17:01:37    Ignoring: .deployment
2019-12-18T17:01:37    Detecting node version spec...
2019-12-18T17:01:37    Using appsetting WEBSITE_NODE_DEFAULT_VERSION value: 10-lts
2019-12-18T17:01:37    Node.js versions available on the platform are: 4.4.7, 4.5.0, 4.8.0, 6.2.2, 6.6.0, 6.9.3, 6.10.3, 6.11.0, 6.17.1, 8.0.0, 8.1.4, 8.2.1, 8.8.1, 8.9.4, 8.11.2, 8.12.0, 8.15.1, 8.16.2, 9.4.0, 10.1.0, 10.10.0, 10.14.2, 10.17.0, 12.13.0.
2019-12-18T17:01:37    Could not resolve node version. Deployment will proceed with default versions of node and npm.
2019-12-18T17:01:37    Running "node" "/usr/bin/npm-cli.js" install --production
2019-12-18T17:01:38    npm WARN npm npm does not support Node.js v12.13.0
2019-12-18T17:01:39    up to date in 0.29s
2019-12-18T17:01:39    npm WARN npm You should probably upgrade to a newer version of node as we
2019-12-18T17:01:39    Finished successfully.
2019-12-18T17:01:39    npm WARN npm can't make any promises that npm will work with this version.
2019-12-18T17:01:39    npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
2019-12-18T17:01:39    npm WARN npm You can find the latest version at https://nodejs.org/
2019-12-18T17:01:39    npm WARN [email protected] No description
2019-12-18T17:01:39    npm WARN [email protected] No repository field.
2019-12-18T17:01:39    
2019-12-18T17:01:39  Running post deployment command(s)...
2019-12-18T17:01:39  Triggering recycle (preview mode disabled).
2019-12-18T17:01:39  Deployment successful.

I think this is a bigger problem that I can't solve...

Well, I've been working with @pesimeao on this issue and the temporary workaround is to set the NPM_CMD to a fixed version (10.14., in our case) in the deploy.sh script and disable the Node version selection (selectNodeVersion) by commenting that line. Our deploy.sh look like this

# Deployment
# ----------

## Force NPM Version
NPM_CMD="node /opt/nodejs/10.14.2/bin/npm"

# 1. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
  "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
  exitWithMessageOnError "Kudu Sync failed"
fi

# disable selectNodeVersion
# 2. Select node version
# selectNodeVersion

This link pointed out to the workaround.

Related to this.

ik wat creating a teams add in and had a sort a like issue and your work around has helped me sooooooo much @morsaPT THX a million

It seems that if you set these environment variables in you App Service Settings, everything runs smoothly. You just have to use versions that match.

WEBSITE_NODE_DEFAULT_VERSION=12
WEBSITE_NPM_DEFAULT_VERSION=6

Same as #3189

Was this page helpful?
0 / 5 - 0 ratings