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