如何让Azure nodejs webapp重新运行npm install?

我正在Azure上运行Node web应用程序。 我使用“local git”方法部署应用程序。 每当我对源代码进行更改,提交,然后使用git push azure master进行部署时,网站上的代码将按预期更新。

但我最近的一个变化包括添加一个新的包到我的package.json文件。 现在,当我部署时,我的文件被更新,但azure似乎并没有重新运行npm install ,并且没有安装新的模块。 这意味着应用程序不会启动:当我的代码调用require('missingModuleName')它会得到一个致命的错误并停止。

上次我有这个问题,我从Azure中删除了应用程序,并从头创build一个新的。 但我希望有一个更简单的解决scheme。

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

安装日志显示: 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.
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.

问题是package-lock.json 。 我在本地使用了旧的npm版本3,并没有创build一个包locking文件(而且我还没准备好收缩包装)。

但Azure上较新的npm版本5创build了一个package-lock.json 。 这似乎优先于package.json

所以我在本地升级npm(花了一段时间才发现我需要nodist npm latest ),并将package-lock.json添加到了我的git package-lock.json中。 然后当它部署,npm花了相当一段时间,但它为我安装了一切。