NodeJS application deployment issue

五迷三道 提交于 2019-12-12 05:39:42

问题


Deployed NodeJS application to Azure from VS Code like mentioned here: Deploy NodeJS app to Azure from VS Code successfully - first initial commit:

$ git push azure master
...
remote: Updating branch 'master'.
remote: Updating submodules.
...

Then added dotenv-extended module to app.js:

require('dotenv-extended').load();

npm added "dotenv-extended": "^2.0.1" to package.json file. After that committed, pushed to github, then pushed to azure same way like above.

However in 2nd time Azure did not perform submodules update and dotenv-extended was not installed on Azure in /node_modules/* which is added to .gitignore on my side. This caused application exception so forced to go to azure and run npm install dotenv-extended or npm update manually.

In 3rd time deployment Azure printed:

remote: Updating branch 'master'.
remote: Updating submodules.
...
remote: npm WARN MyApp@1.0.0 No description
remote: removed 15 packages in 31.134s
remote: npm WARN MyApp@1.0.0 No repository field.

and when I checked dotenv-extended was erased again even if I installed it manually previously.

  • Why did this happen, why azure did not run remote: Updating submodules in second time?
  • How to fix this if I need to add some modules later?
  • Is it possible to fix or extend some post-deployment script on Azure to add npm update command?
  • Or install them manually which is not good?
  • Or there is another way to deploy without git?

P.S. Think proposed solution Git push to azure websites with submodule will not work as Git Azure erases modules for some reason.


回答1:


It looks like it's having trouble loading modules. By default, Azure Web Apps’ deployment task uses npm install --production command to install the dependencies in your package.json, which will skip all the dependencies configured in devDependencies section. So please make sure dotenv-extended is placed in dependencies.




回答2:


Note. Custom Deployment Script method, mentioned below, overrides Azure default method and sources not copied to wwwroot. Need another or more detailed solution.

According to Custom Deployment Script added a file to the root of my git repository with the name .deployment and the content:

[config]
command = cd %DEPLOYMENT_TARGET% && echo "npm update ..." && npm update --quiet

Works for now however increases deployment time, will see more if another module added.




回答3:


Seems some Azure issue it uses kudusync npm module for repository and wwwroot synchronizations and works wrong way. Following sequence helped me to solve the issue:

  • Go to Kudu in Azure,
  • Open Debug Console -> CMD there
  • Execute:
    • cd D:\home\site\repository>
    • npm udpate
    • cd D:\home\site\wwwroot>
    • npm udpate For some reason Azure script install npm modules in repository dir only on first deployment, and do not update it further. Above commands allow to synchronize repository and wwwroot directories and prevent removing packages not present in repository from wwwroot. However need to do this on every added package.

Works fine now after all of above. People suggest to commit package-lock.json, however this solution had not helped me: Azure deployment script uninstalls modules not present in D:\home\site\repository> from D:\home\site\wwwroot> and I get above error.



来源:https://stackoverflow.com/questions/45656121/nodejs-application-deployment-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!