如何使Azure Node.js Web应用重新运行npm安装? [英] How to make Azure nodejs webapp re-run npm install?

查看:89
本文介绍了如何使Azure Node.js Web应用重新运行npm安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Azure上运行Node webapp。
我使用本地git方法部署应用程序。
每次我更改源代码,提交并使用 git push azure master 进行部署时,网站上的代码都会按预期进行更新。

但是我最近的更改之一是在我的 package.json 文件中添加了一个新软件包。现在,当我进行部署时,我的文件已更新,但是azure似乎没有重新运行 npm install ,并且未安装新模块。这意味着该应用程序无法启动:当我的代码调用 require('missingModuleName')时,它将出现致命错误并停止。



上次出现此问题时,我从Azure中删除了该应用程序,并从头开始创建了一个新应用程序。但我希望有一个更简单的解决方案。



我看到了(在 https://github.com/projectkudu/kudu/wiki/Deployment ),在部署时对于Node站点,Kudu在wwwroot文件夹中运行 npm install。我不确定标准的本地git部署方法是否会调用Kudu部署过程。我是否需要创建一个部署挂钩(如 https://github.com/中所述projectkudu / kudu / wiki / Deployment-hooks )?



安装日志显示:
2017-07-29T07 :59:51正在更新分支 master。
2017-07-29T07:59:52更新子模块。
2017-07-29T07:59:52正在准备提交ID为 556a34aab5的部署。
2017-07-29T07:59:52正在运行自定义部署命令...
2017-07-29T07:59:52正在运行部署命令...
2017-07-29T07:59 :52命令:deploy.cmd
2017-07-29T07:59:53处理node.js部署。
2017-07-29T07:59:53 KuduSync.NET从:'D:\home\site\repository'到:'D:\home\site\wwwroot'
2017-07-29T07:59:53复制文件:'package.json'
2017-07-29T07:59:53在站点根目录下查找app.js / server.js。
2017-07-29T07:59:53使用启动脚本server.js
2017-07-29T07:59:55平台上可用的Node.js版本为:0.6.20,0.8。 2,0.8.19,0.8.26,0.8.27,0.8.28,0.10.5,0.10.18,0.10.21,0.10.24,0.10.26,0.10.28,0.10.29,0.10.31, 0.10.32、0.10.40、0.12.0、0.12.2、0.12.3、0.12.6、4.0.0、4.1.0、4.1.2、4.2.1、4.2.2、4.2.3、4.2。 4,4.3.0,4.3.2,4.4.0,4.4.1,4.4.6,4.4.7,4.5.0,4.6.0,4.6.1,4.8.4,5.0.0,5.1.1, 5.3.0、5.4.0、5.5.0、5.6.0、5.7.0、5.7.1、5.8.0、5.9.1、6.0.0、6.1.0、6.2.2、6.3.0、6.5。 0,6.6.0,6.7.0,6.9.0,6.9.1,6.9.2,6.9.4,6.9.5,6.10.0,6.11.1,7.0.0,7.1.0,7.2.0, 7.3.0、7.4.0、7.5.0、7.6.0、7.7.4、7.10.0、7.10.1、8.0.0、8.1.4。
2017-07-29T07:59:55选择的node.js版本8.1.4。使用package.json文件选择其他版本。
2017-07-29T07:59:55选定的npm版本5.0.3
2017-07-29T07:59:56在D:\home\site\wwwroot\更新iisnode.yml iisnode.yml
2017-07-29T07:59:56 npm WARN生命周期用于脚本的节点二进制文件是D:\Program Files(x86)\nodejs\0.10.28\node.exe但npm正在使用D:\程序文件(x86)\nodejs\8.1.4\node.exe本身。使用--scripts-prepend-node-path选项可以包含执行二进制二进制文件npm的路径。
2017-07-29T08:00:03 npm WARN护照-azure-ad-login-oidc@0.0.1没有存储库字段。
2017-07-29T08:00:03在7.206s中是最新的
2017-07-29T08:00:03 npm WARNpassport-azure-ad-login-oidc@0.0.1没有许可证字段。
2017-07-29T08:00:03

2017-07-29T08:00:03已成功完成。
2017-07-29T08:00:03正在运行部署后命令...
2017-07-29T08:00:03部署成功。

解决方案

问题在于 package-lock。 json 。我在本地使用的是旧的npm版本3,但没有创建程序包锁定文件(而且我还没有准备好进行拆封)。



但是Azure did 上较新的npm版本5创建了 package-lock.json 。似乎优先于 package.json



所以我在本地升级了npm(花了一段时间查找我需要 nodist npm最新来执行此操作),然后将 package-lock.json 添加到我的git存储库中。然后在部署时,npm花了很长时间,但它为我安装了所有东西。


I'm running a Node webapp on Azure. I deploy the app using the "local git" method. Every time I make changes to my source, commit, and then deploy with git push azure master, the code on the site is updated, as expected.

But one of my recent changes included adding a new package to my package.json file. Now when I deploy, my files are updated, but azure doesn't seem to re-run npm install, and the new modules are not installed. This means that the app doesn't start: when my code calls require('missingModuleName') it gets a fatal error and stops.

Last time I had this problem, I removed the app from Azure, and created a new one from scratch. But I hope that there's a simpler solution.

I see (at https://github.com/projectkudu/kudu/wiki/Deployment) that on deployment "For Node sites, Kudu runs 'npm install' in the wwwroot folder". I'm not sure whether the standard "local git" deployment method invokes the Kudu deployment process. Do I need to create a deployment hook (as described in https://github.com/projectkudu/kudu/wiki/Deployment-hooks)?

The installation log shows: 2017-07-29T07:59:51 Updating branch 'master'. 2017-07-29T07:59:52 Updating submodules. 2017-07-29T07:59:52 Preparing deployment for commit id '556a34aab5'. 2017-07-29T07:59:52 Running custom deployment command... 2017-07-29T07:59:52 Running deployment command... 2017-07-29T07:59:52 Command: deploy.cmd 2017-07-29T07:59:53 Handling node.js deployment. 2017-07-29T07:59:53 KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot' 2017-07-29T07:59:53 Copying file: 'package.json' 2017-07-29T07:59:53 Looking for app.js/server.js under site root. 2017-07-29T07:59:53 Using start-up script server.js 2017-07-29T07:59:55 Node.js versions available on the platform are: 0.6.20, 0.8.2, 0.8.19, 0.8.26, 0.8.27, 0.8.28, 0.10.5, 0.10.18, 0.10.21, 0.10.24, 0.10.26, 0.10.28, 0.10.29, 0.10.31, 0.10.32, 0.10.40, 0.12.0, 0.12.2, 0.12.3, 0.12.6, 4.0.0, 4.1.0, 4.1.2, 4.2.1, 4.2.2, 4.2.3, 4.2.4, 4.3.0, 4.3.2, 4.4.0, 4.4.1, 4.4.6, 4.4.7, 4.5.0, 4.6.0, 4.6.1, 4.8.4, 5.0.0, 5.1.1, 5.3.0, 5.4.0, 5.5.0, 5.6.0, 5.7.0, 5.7.1, 5.8.0, 5.9.1, 6.0.0, 6.1.0, 6.2.2, 6.3.0, 6.5.0, 6.6.0, 6.7.0, 6.9.0, 6.9.1, 6.9.2, 6.9.4, 6.9.5, 6.10.0, 6.11.1, 7.0.0, 7.1.0, 7.2.0, 7.3.0, 7.4.0, 7.5.0, 7.6.0, 7.7.4, 7.10.0, 7.10.1, 8.0.0, 8.1.4. 2017-07-29T07:59:55 Selected node.js version 8.1.4. Use package.json file to choose a different version. 2017-07-29T07:59:55 Selected npm version 5.0.3 2017-07-29T07:59:56 Updating iisnode.yml at D:\home\site\wwwroot\iisnode.yml 2017-07-29T07:59:56 npm WARN lifecycle The node binary used for scripts is D:\Program Files (x86)\nodejs\0.10.28\node.exe but npm is using D:\Program Files (x86)\nodejs\8.1.4\node.exe itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with. 2017-07-29T08:00:03 npm WARN passport-azure-ad-login-oidc@0.0.1 No repository field. 2017-07-29T08:00:03 up to date in 7.206s 2017-07-29T08:00:03 npm WARN passport-azure-ad-login-oidc@0.0.1 No license field. 2017-07-29T08:00:03
2017-07-29T08:00:03 Finished successfully. 2017-07-29T08:00:03 Running post deployment command(s)... 2017-07-29T08:00:03 Deployment successful.

解决方案

The problem was with package-lock.json. I was using an old npm version 3 locally, and it didn't create a package lock file (and I wasn't ready for shrinkwrap).

But the newer npm version 5 on Azure did create a package-lock.json. That seems to take precedence over the package.json.

So I upgraded npm locally (took a while to find that I needed nodist npm latest to do it), and added the package-lock.json to my git repo. Then when it deployed, npm took quite some time but it installed everything for me.

这篇关于如何使Azure Node.js Web应用重新运行npm安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆