【问题标题】:How to make Azure nodejs webapp re-run npm install?如何让 Azure nodejs webapp 重新运行 npm install?
【发布时间】:2017-07-30 06:03:43
【问题描述】:

我在 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 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.

【问题讨论】:

  • 为了帮助隔离,如果您使用 Kudu 控制台从 site/wwwroot 手动运行 npm install 会发生什么?

标签: node.js azure deployment azure-web-app-service npm-install


【解决方案1】:

问题在于package-lock.json。我在本地使用旧的 npm 版本 3,它没有创建包锁定文件(而且我还没有准备好收缩包装)。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-13
    • 2019-01-23
    • 2022-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 2016-05-03
    相关资源
    最近更新 更多