0

I am trying to deploy node js application on Azure app service. The application files and node_modules folder is created as expected but the app fails to start with the below errors

 2021-02-10T04:22:12.727825432Z npm ERR! code EPERM
2021-02-10T04:22:12.734836329Z npm ERR! syscall lchown
2021-02-10T04:22:12.734870329Z npm ERR! path /home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver
2021-02-10T04:22:12.754015919Z npm ERR! errno -1
2021-02-10T04:22:12.754037719Z npm ERR! Error: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver'
2021-02-10T04:22:12.754053319Z npm ERR!  [OperationalError: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver'] {
2021-02-10T04:22:12.754058419Z npm ERR!   cause: [Error: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver'] {
2021-02-10T04:22:12.754062319Z npm ERR!     errno: -1,
2021-02-10T04:22:12.754065719Z npm ERR!     code: 'EPERM',
2021-02-10T04:22:12.754069319Z npm ERR!     syscall: 'lchown',
2021-02-10T04:22:12.754073019Z npm ERR!     path: '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver'
2021-02-10T04:22:12.754076719Z npm ERR!   },
2021-02-10T04:22:12.754097119Z npm ERR!   errno: -1,
2021-02-10T04:22:12.754100719Z npm ERR!   code: 'EPERM',
2021-02-10T04:22:12.754104319Z npm ERR!   syscall: 'lchown',
2021-02-10T04:22:12.754107819Z npm ERR!   path: '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver',
2021-02-10T04:22:12.754111519Z npm ERR!   parent: 'istanbul-lib-instrument'
2021-02-10T04:22:12.758140417Z npm ERR! }
2021-02-10T04:22:12.761503315Z npm ERR! 
2021-02-10T04:22:12.762563214Z npm ERR! The operation was rejected by your operating system.
2021-02-10T04:22:12.763983914Z npm ERR! It is likely you do not have the permissions to access this file as the current user
2021-02-10T04:22:12.764467213Z npm ERR! 
2021-02-10T04:22:12.765574713Z npm ERR! If you believe this might be a permissions issue, please double-check the
2021-02-10T04:22:12.769113211Z npm ERR! permissions of the file and its containing directories, or try running
2021-02-10T04:22:12.769133011Z npm ERR! the command again as root/Administrator.

it is Linux based app service. Startup command - npm install && npm start

node version 12. NPM - 6.14

the application worked on first deployment but failing for all further deployments

i am stuck on this for 2 days. Thanks in advance

  • Here is an answer I post steps using DevOps deploying node project, you could have a look. https://stackoverflow.com/questions/64758494/deploy-stripe-payment-gateway-on-azure/64783120#64783120 – Doris Lv Feb 10 '21 at 07:49
  • The issue is resolved by npm install during before deployment and using just npm start as run command in app service. Also the comment from Doris works out well. Thank you –  Feb 12 '21 at 05:14

2 Answers2

0

Azure deployment fails for Node js application : npm ERR! code EPERM

You could try to clean the npm cache by the command line:

npm cache clean --force

If it not work for you, please remove the cache files manually. To do so go to the default NPM cache folder and remove its content:

Default: ~/.npm on linux, or %AppData%/npm-cache on Window

Then you can attempt to install and start your the app.

Note:

Avoid using sudo npm install -g because you may mess up the npm permissions. Instead change the permission to npm's default directory, or change npm's default directory to another directory. Further details here: https://docs.npmjs.com/getting-started/fixing-npm-permissions

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    Thank you Leo. I tried cleaning the cache and reinstalled the npm packages, the issue was fixed on the first deployment but continues to get the same error on further deployments. I somewhat managed to resolve the issue by doing NPM install again after the build and used npm start as start up command instead of npm install && npm start –  Feb 12 '21 at 05:10
  • @user88, Thanks for your reply. So, have you resolved this issue now? If yes, would you please convert your comment to the answer? This can be beneficial to other community members reading the answer, avoid spending a lot of time on a post that already has an answer. Thanks. – Leo Liu Feb 12 '21 at 05:12
0

I was able to fix the issue in two ways.

  1. After the build in Pipeline, did NPM install to include node_modules folder and did the deployment. The npm start at the app service start command runs the app.

  2. Follow this link Used the link suggested by Doris and everything worked fine.