title: How to run a postinstall script when publishing angular4 app to azure website using kuduscript?
body: <p>I have an angular4 app that is deployed to azure web app (website) by configuring Deployment Options via Portal.
  I used kuduscript to create custom deployment script [<code>kuduscript -y –node</code>] and then edited <code>deploy.cmd</code> to tell azure how to run angular app.</p>
  <p>Dependencies were adjusted in <code>package.json</code>. The prod build [<code>ng build --prod</code>] runs fine locally, but creates an error in azure:</p>
  <blockquote>
  <p>Failed at the ng2project@0.0.2 postinstall script 'node ./node_modules/protractor/bin/webdriver-manager update'</p>
  <p>Error: Cannot find module 'D:\home\site\repository\node_modules\protractor\bin\webdriver-manager' at Function.Module._resolveFilename ....</p>
  </blockquote>
  <p>This is because of the <code>postinstall</code> under <code>scripts</code> in <code>package.json</code></p>
  <pre><code>&quot;scripts&quot;: {
    &quot;ng&quot;: &quot;ng&quot;,
    &quot;build&quot;: &quot;ng build&quot;,
    &quot;test&quot;: &quot;ng test&quot;,
    &quot;lint&quot;: &quot;ng lint&quot;,
    &quot;modernizr&quot;: &quot;modernizr -c modernizr-config.json -d src/modernizr.js&quot;,
    &quot;postinstall&quot;: &quot;node ./node_modules/protractor/bin/webdriver-manager update&quot;,
    &quot;e2e&quot;: &quot;ng e2e&quot;
  }
  </code></pre>
  <p>If I remove it, build works fine. I suspect its because the files are transferred to <code>wwwroot</code> folder from <code>respository</code> folder before <code>postinstall</code> gets called. Looking for pointers on how to fix this.</p>
  <p>This is the modified <code>deploy.cmd</code> in use:</p>
  <pre><code>    @if &quot;%SCM_TRACE_LEVEL%&quot; NEQ &quot;4&quot; @echo off
      :: ----------------------
      :: KUDU Deployment Script
      :: Version: 1.0.15
      :: ----------------------
  
      :: Prerequisites
      :: -------------
  
      :: Verify node.js installed
      where node 2&gt;nul &gt;nul
      IF %ERRORLEVEL% NEQ 0 (
        echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
        goto error
      )
  
      :: Setup
      :: -----
  
      setlocal enabledelayedexpansion
  
      SET ARTIFACTS=%~dp0%..\artifacts
  
      IF NOT DEFINED DEPLOYMENT_SOURCE (
        SET DEPLOYMENT_SOURCE=%~dp0%.
      )
  
      IF NOT DEFINED DEPLOYMENT_TARGET (
        SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
      )
  
      IF NOT DEFINED NEXT_MANIFEST_PATH (
        SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest
  
        IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
          SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
        )
      )
  
      IF NOT DEFINED KUDU_SYNC_CMD (
        :: Install kudu sync
        echo Installing Kudu Sync
        call npm install kudusync -g --silent
        IF !ERRORLEVEL! NEQ 0 goto error
  
        :: Locally just running &quot;kuduSync&quot; would also work
        SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
      )
      goto Deployment
  
      :: Utility Functions
      :: -----------------
  
      :SelectNodeVersion
  
      IF DEFINED KUDU_SELECT_NODE_VERSION_CMD (
        :: The following are done only on Windows Azure Websites environment
        call %KUDU_SELECT_NODE_VERSION_CMD% &quot;%DEPLOYMENT_SOURCE%&quot; &quot;%DEPLOYMENT_TARGET%&quot; &quot;%DEPLOYMENT_TEMP%&quot;
        IF !ERRORLEVEL! NEQ 0 goto error
  
        IF EXIST &quot;%DEPLOYMENT_TEMP%\__nodeVersion.tmp&quot; (
          SET /p NODE_EXE=&lt;&quot;%DEPLOYMENT_TEMP%\__nodeVersion.tmp&quot;
          IF !ERRORLEVEL! NEQ 0 goto error
        )
        
        IF EXIST &quot;%DEPLOYMENT_TEMP%\__npmVersion.tmp&quot; (
          SET /p NPM_JS_PATH=&lt;&quot;%DEPLOYMENT_TEMP%\__npmVersion.tmp&quot;
          IF !ERRORLEVEL! NEQ 0 goto error
        )
  
        IF NOT DEFINED NODE_EXE (
          SET NODE_EXE=node
        )
  
        SET NPM_CMD=&quot;!NODE_EXE!&quot; &quot;!NPM_JS_PATH!&quot;
      ) ELSE (
        SET NPM_CMD=npm
        SET NODE_EXE=node
      )
  
      goto :EOF
  
      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      :: Deployment
      :: ----------
  
      :Deployment
      echo Handling node.js deployment.
  
      :: 1. Select node version
      call :SelectNodeVersion
  
      :: 2. Install npm packages
      IF EXIST &quot;%DEPLOYMENT_SOURCE%\package.json&quot; (
        pushd &quot;%DEPLOYMENT_SOURCE%&quot;
        call :ExecuteCmd !NPM_CMD! install --production
        IF !ERRORLEVEL! NEQ 0 goto error
        popd
      )
  
      :: 3. Angular Prod Build
      IF EXIST &quot;%DEPLOYMENT_SOURCE%/.angular-cli.json&quot; (
      echo Building App in %DEPLOYMENT_SOURCE%…
      pushd &quot;%DEPLOYMENT_SOURCE%&quot;
      call :ExecuteCmd !NPM_CMD! run build
      :: If the above command fails comment above and uncomment below one
      :: call ./node_modules/.bin/ng build –prod
      IF !ERRORLEVEL! NEQ 0 goto error
      popd
      )
  
      :: 4. KuduSync
      IF /I &quot;%IN_PLACE_DEPLOYMENT%&quot; NEQ &quot;1&quot; (
        call :ExecuteCmd &quot;%KUDU_SYNC_CMD%&quot; -v 50 -f &quot;%DEPLOYMENT_SOURCE%/dist&quot; -t &quot;%DEPLOYMENT_TARGET%&quot; -n &quot;%NEXT_MANIFEST_PATH%&quot; -p &quot;%PREVIOUS_MANIFEST_PATH%&quot; -i &quot;.git;.hg;.deployment;deploy.cmd&quot;
        IF !ERRORLEVEL! NEQ 0 goto error
      )
      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      goto end
  
      :: Execute command routine that will echo out when error
      :ExecuteCmd
      setlocal
      set _CMD_=%*
      call %_CMD_%
      if &quot;%ERRORLEVEL%&quot; NEQ &quot;0&quot; echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
      exit /b %ERRORLEVEL%
  
      :error
      endlocal
      echo An error has occurred during web site deployment.
      call :exitSetErrorLevel
      call :exitFromFunction 2&gt;nul
  
      :exitSetErrorLevel
      exit /b 1
  
      :exitFromFunction
      ()
  
      :end
      endlocal
      echo Finished successfully.
  </code></pre>
  <p>Full <code>package.json</code>:</p>
  <pre><code>{
    &quot;name&quot;: &quot;ng2project&quot;,
    &quot;version&quot;: &quot;0.0.2&quot;,
    &quot;license&quot;: &quot;MPL-2.0&quot;,
    &quot;scripts&quot;: {
      &quot;ng&quot;: &quot;ng&quot;,
      &quot;build&quot;: &quot;ng build --prod&quot;,
      &quot;test&quot;: &quot;ng test&quot;,
      &quot;lint&quot;: &quot;ng lint&quot;,
      &quot;modernizr&quot;: &quot;modernizr -c modernizr-config.json -d src/modernizr.js&quot;,
      &quot;postinstall&quot;: &quot;node ./node_modules/protractor/bin/webdriver-manager update&quot;,
      &quot;e2e&quot;: &quot;ng e2e&quot;
    },
    &quot;private&quot;: true,
    &quot;napa&quot;: {
      &quot;jquery.flot.spline&quot;: &quot;miloszfalinski/jquery.flot.spline&quot;,
      &quot;ika.jvectormap&quot;: &quot;kakirigi/ika.jvectormap&quot;,
      &quot;flot&quot;: &quot;flot/flot#v0.8.3&quot;
    },
    &quot;dependencies&quot;: {
      &quot;@agm/core&quot;: &quot;1.0.0-beta.0&quot;,
      &quot;@angular/animations&quot;: &quot;4.3.3&quot;,
      &quot;@angular/cli&quot;: &quot;1.3.2&quot;,
      &quot;@angular/common&quot;: &quot;4.3.3&quot;,
      &quot;@angular/compiler&quot;: &quot;4.3.3&quot;,
      &quot;@angular/compiler-cli&quot;: &quot;4.3.3&quot;,
      &quot;@angular/core&quot;: &quot;4.3.3&quot;,
      &quot;@angular/forms&quot;: &quot;4.3.3&quot;,
      &quot;@angular/http&quot;: &quot;4.3.3&quot;,
      &quot;@angular/platform-browser&quot;: &quot;4.3.3&quot;,
      &quot;@angular/platform-browser-dynamic&quot;: &quot;4.3.3&quot;,
      &quot;@angular/router&quot;: &quot;4.3.3&quot;,
      &quot;@ngx-translate/core&quot;: &quot;7.1.0&quot;,
      &quot;@ngx-translate/http-loader&quot;: &quot;1.0.1&quot;,
      &quot;@types/node&quot;: &quot;^6.0.60&quot;,
      &quot;ag-grid&quot;: &quot;12.0.2&quot;,
      &quot;ag-grid-angular&quot;: &quot;12.0.0&quot;,
      &quot;angular-tree-component&quot;: &quot;3.9.0&quot;,
      &quot;angular2-datatable&quot;: &quot;0.6.0&quot;,
      &quot;angular2-text-mask&quot;: &quot;8.0.3&quot;,
      &quot;angular2-toaster&quot;: &quot;^4.0.1&quot;,
      &quot;angularx-qrcode&quot;: &quot;^1.0.1&quot;,
      &quot;bootstrap&quot;: &quot;3.3.7&quot;,
      &quot;chart.js&quot;: &quot;2.6.0&quot;,
      &quot;classlist.js&quot;: &quot;1.1.20150312&quot;,
      &quot;codemirror&quot;: &quot;5.28.0&quot;,
      &quot;core-js&quot;: &quot;2.4.1&quot;,
      &quot;easy-pie-chart&quot;: &quot;2.1.7&quot;,
      &quot;enhanced-resolve&quot;: &quot;3.3.0&quot;,
      &quot;font-awesome&quot;: &quot;4.7.0&quot;,
      &quot;fullcalendar&quot;: &quot;3.4.0&quot;,
      &quot;intl&quot;: &quot;1.2.5&quot;,
      &quot;jqcloud2&quot;: &quot;2.0.3&quot;,
      &quot;jquery&quot;: &quot;3.2.1&quot;,
      &quot;jquery-slimscroll&quot;: &quot;1.3.8&quot;,
      &quot;jquery-sparkline&quot;: &quot;2.4.0&quot;,
      &quot;jquery.browser&quot;: &quot;0.1.0&quot;,
      &quot;jquery.flot.tooltip&quot;: &quot;github:krzysu/flot.tooltip&quot;,
      &quot;loaders.css&quot;: &quot;^0.1.2&quot;,
      &quot;lodash&quot;: &quot;4.17.4&quot;,
      &quot;modernizr&quot;: &quot;3.5.0&quot;,
      &quot;moment&quot;: &quot;2.18.1&quot;,
      &quot;ng2-charts&quot;: &quot;1.6.0&quot;,
      &quot;ng2-device-detector&quot;: &quot;^1.0.1&quot;,
      &quot;ng2-dnd&quot;: &quot;4.2.0&quot;,
      &quot;ng2-file-upload&quot;: &quot;1.2.1&quot;,
      &quot;ng2-img-cropper&quot;: &quot;0.9.0&quot;,
      &quot;ng2-select&quot;: &quot;1.2.0&quot;,
      &quot;ng2-table&quot;: &quot;1.3.2&quot;,
      &quot;ng2-validation&quot;: &quot;4.2.0&quot;,
      &quot;ngx-bootstrap&quot;: &quot;1.8.1&quot;,
      &quot;ngx-chips&quot;: &quot;1.5.3&quot;,
      &quot;ngx-color-picker&quot;: &quot;4.2.0&quot;,
      &quot;ngx-infinite-scroll&quot;: &quot;0.5.1&quot;,
      &quot;ngx-webstorage&quot;: &quot;^1.8.0&quot;,
      &quot;node-sass&quot;: &quot;4.5.3&quot;,
      &quot;rxjs&quot;: &quot;5.4.2&quot;,
      &quot;screenfull&quot;: &quot;3.3.1&quot;,
      &quot;simple-line-icons&quot;: &quot;2.4.1&quot;,
      &quot;socket.io-client&quot;: &quot;^2.0.4&quot;,
      &quot;spinkit&quot;: &quot;1.2.5&quot;,
      &quot;summernote&quot;: &quot;0.8.6&quot;,
      &quot;sweetalert&quot;: &quot;^1.1.3&quot;,
      &quot;ts-helpers&quot;: &quot;1.1.1&quot;,
      &quot;typescript&quot;: &quot;2.3.3&quot;,
      &quot;weather-icons&quot;: &quot;github:erikflowers/weather-icons&quot;,
      &quot;web-animations-js&quot;: &quot;2.2.1&quot;,
      &quot;zone.js&quot;: &quot;0.8.14&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@angular/cli&quot;: &quot;1.3.2&quot;,
      &quot;@angular/compiler-cli&quot;: &quot;4.3.3&quot;,
      &quot;@angular/language-service&quot;: &quot;4.3.3&quot;,
      &quot;@types/codemirror&quot;: &quot;0.0.43&quot;,
      &quot;@types/jasmine&quot;: &quot;2.5.53&quot;,
      &quot;@types/jasminewd2&quot;: &quot;2.0.2&quot;,
      &quot;@types/lodash&quot;: &quot;4.14.71&quot;,
      &quot;@types/node&quot;: &quot;6.0.60&quot;,
      &quot;codelyzer&quot;: &quot;3.1.1&quot;,
      &quot;jasmine-core&quot;: &quot;2.6.2&quot;,
      &quot;jasmine-spec-reporter&quot;: &quot;4.1.0&quot;,
      &quot;karma&quot;: &quot;1.7.0&quot;,
      &quot;karma-chrome-launcher&quot;: &quot;2.1.1&quot;,
      &quot;karma-cli&quot;: &quot;1.0.1&quot;,
      &quot;karma-coverage-istanbul-reporter&quot;: &quot;1.2.1&quot;,
      &quot;karma-jasmine&quot;: &quot;1.1.0&quot;,
      &quot;karma-jasmine-html-reporter&quot;: &quot;0.2.2&quot;,
      &quot;karma-read-json&quot;: &quot;1.1.0&quot;,
      &quot;loaders.css&quot;: &quot;0.1.2&quot;,
      &quot;napa&quot;: &quot;3.0.0&quot;,
      &quot;protractor&quot;: &quot;5.1.2&quot;,
      &quot;ts-node&quot;: &quot;3.2.0&quot;,
      &quot;tslint&quot;: &quot;5.3.2&quot;,
      &quot;typescript&quot;: &quot;2.3.3&quot;,
      &quot;webdriver-manager&quot;: &quot;10.2.5&quot;
    }
  }
  </code></pre>
  <p>References:
  <a href="https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script" rel="nofollow noreferrer">https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script</a></p>