NodeJS应用程序部署问题
从VS Code将NodeJS应用程序部署到Azure,如下所述:从VS Code成功将NodeJS应用程序部署到Azure -首先初始提交:
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.
...
然后将dotenv-extended
模块添加到app.js
:
require('dotenv-extended').load();
npm 已将"dotenv-extended": "^2.0.1"
添加到package.json
文件.提交后,推送到github,然后像上面一样推送到天蓝色.
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.
但是第2次,Azure未执行子模块更新,并且/node_modules/*
未安装在/node_modules/*
中的Azure上,而在我这边的.gitignore
中已添加了dotenv-extended
.这导致了应用程序异常,因此不得不使用Azure手动运行npm install dotenv-extended
或npm update
.
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.
第3次部署Azure打印:
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.
,并且当我检查dotenv-extended
时,即使以前手动安装,它也会被再次擦除.
and when I checked dotenv-extended
was erased again even if I installed it manually previously.
- 为什么会这样,为什么azure第二次没有运行
remote: Updating submodules
? - 如果以后需要添加一些模块,该如何解决?
- 是否可以在Azure上修复或扩展某些部署后脚本以添加
npm update
命令? - 还是手动安装它们不好?
- 还是没有git的另一种部署方式?
- 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.考虑提出的解决方案 Git推送到带有子模块的天蓝色网站不能作为Git Azure使用 出于某种原因擦除模块.
P.S. Think proposed solution Git push to azure websites with submodule will not work as Git Azure erases modules for some reason.
似乎有些Azure问题,它使用kudusync
npm 模块进行repository
和wwwroot
同步,并且工作方式错误.以下顺序可帮助我解决问题:
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:
- 转到Azure中的
Kudu
- 在那里打开
Debug Console -> CMD
- 执行:
- cd
D:\home\site\repository>
-
npm udpate
- cd
D:\home\site\wwwroot>
-
npm udpate
出于某种原因,Azure脚本仅在第一次部署时在repository
目录中安装npm模块,并且不对其进行进一步更新.上面的命令允许同步repository
和wwwroot
目录,并防止从wwwroot
中删除repository
中不存在的软件包.但是,需要在每个添加的软件包上执行此操作.
- 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 inrepository
dir only on first deployment, and do not update it further. Above commands allow to synchronizerepository
andwwwroot
directories and prevent removing packages not present inrepository
fromwwwroot
. However need to do this on every added package.
以上所有方法现在都可以正常工作.人们建议提交
package-lock.json
,但是此解决方案没有帮助我:Azure部署脚本卸载从 D:\home\site\wwwroot>
中,我得到了上面的错误.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 inD:\home\site\repository>
fromD:\home\site\wwwroot>
and I get above error. - cd
- cd