简体   繁体   English

Azure网站中的NPM错误和控制

[英]NPM errors and control in Azure Websites

I want to build my Node.JS application in a Azure Website . 我想在Azure网站中构建Node.JS应用程序。
There will be an usage of different NPM packages via my packages.json file. 我的packages.json文件将使用不同的NPM软件包。
My problem is that I often receive error messages which are related to missing NPM files. 我的问题是我经常收到与缺少NPM文件有关的错误消息。

Normally I put my files via FTP or edit them per VS Studio 15 Azure plugin directly on the server. 通常,我通过FTP放置文件,或者直接在服务器上根据VS Studio 15 Azure插件编辑文件。 This may be the reason why NPM isn't triggering as Microsoft intended it. 这可能是NPM未按Microsoft预期触发的原因。

I would prefer a way in which I can just run commands with elevated privileges to have full control over NPM by myself. 我希望我可以只使用特权更高的命令运行命令来完全控制NPM。 Which ways are possible to avaid these problems? 有哪些方法可以解决这些问题?

If you're publishing your nodeJS application 'manually' via FTP there are little concerns about that. 如果您要通过FTP“手动”发布nodeJS应用程序,则无需担心。

First of All, 'manually' means manually. 首先,“手动”是指手动。

Git 吉特

If you use continuous deployment via Git the final deployment step is to call npm install in your current application folder, this will install all the packages listed in package.json file. 如果您通过Git使用连续部署,则最后的部署步骤是在当前应用程序文件夹中调用npm install ,这将安装package.json文件中列出的所有软件包。

The node_modules folder is excluded by default in .gitignore file, so all packages are downloaded by the server 默认情况下, .gitignore文件中排除了node_modules文件夹,因此所有软件包均由服务器下载

Web deployment Web部署

If you're using web deployment from visual studio or command line, all the file s contained by your solution are copied to Hosting environment including node_modules folder , because of this the deployment would take a long time to finish due the huge amount of dependencies and files that the folder contains. 如果您使用Visual Studio或命令行中的Web部署, 解决方案中包含的所有文件都将被复制到Hosting环境中,包括node_modules文件夹,因此,由于存在大量的依赖项,因此部署将需要很长时间才能完成该文件夹包含的文件。

Even worst: this scenario could take you to the same scenario you're facing right now. 更糟糕的是:这种情况可能会带您到现在正面临的相同情况。

FTP deployment FTP部署

You're copying everything yourself. 您正在自己复制所有内容。 So the same thing occurs in Web Deployment is happen in FTP deployment method. 因此,在Web部署中发生的同一件事在FTP部署方法中发生。

-- The thing is that when you copy all those node_modules folder contents you're assuming that those dependencies remains the same in the target enviroment, most of the cases that's true, but not always. -事实是,当您复制所有那些node_modules文件夹内容时,您假设这些依赖关系在目标环境中保持相同,大多数情况是正确的,但并非总是如此。

Some dependencies are platform dependent so maybe in you're dev environment a dependency works ok in x86 architectures but what if your target machine or website (or some mix between them) is x64 (real case I already suffer it). 有些依赖关系是平台依赖的,所以也许在您的开发环境中,依赖关系在x86体系结构中可以正常工作,但是如果您的目标机器或网站(或它们之间的某种混合)是x64(真实情况下我已经受了它)。

Other related issues could happen. 其他相关问题也可能发生。 May be your direct dependencies doesn't have the problem but the linked dependencies to them could have it. 可能是您的直接依赖项没有问题,但是链接到它们的依赖项可能有问题。

So always is strongly recommended to run npm install in your target environment and avoid to copy the dependencies directly from your dev environment. 因此,强烈建议始终在目标环境中运行npm install ,并避免直接从开发环境中复制依赖项。

In that way you need to copy on your target environment the folder structure excluding node_modules folder. 这样,您需要在目标环境上复制除node_modules文件夹以外的文件夹结构。 And then when files are copied you need to run npm install on the server. 然后,在复制文件时,您需要在服务器上运行npm install

To achieve that you could go to 要实现这一目标,您可以

yoursitename.scm.azurewebsites.net yoursitename.scm.azurewebsites.net

There you can goto "Debug Console" Tab, then goto this directory D:\\home\\site\\wwwroot> and run 在那里,您可以转到“调试控制台”选项卡,然后转到此目录D:\\home\\site\\wwwroot>并运行

npm install

After that the packages and dependencies are downloaded for the server/website architecture. 之后,为服务器/网站体系结构下载软件包和依赖项。

Hope this helps. 希望这可以帮助。

Azure tweak the Kudu output settings, in local Kudu implementations looks the output is normalized. Azure调整了Kudu输出设置,在本地Kudu实现中看起来输出已标准化。

A workaround -non perfect- could be this 解决方法-不够完美-可能是这样

npm install --dd

Or even more detailed 甚至更详细

npm install --ddd

The most related answer from Microsoft itself is this Microsoft本身最相关的答案是
Using Node.js Modules with Azure applications 将Node.js模块与Azure应用程序一起使用

Regarding control via a console with elevated privileges there is the way of using the Kudu console . 关于通过具有提升特权控制台进行控制,可以使用Kudu控制台 But the error output is quite weird. 但是错误输出很奇怪。 It's kind of putting blindly commands in the console without much feedback. 这是将命令盲目地放在控制台中而没有太多反馈的情况。

Maybe this is a way to go. 也许是一条路。 But I didn't tried this yet. 但是我还没有尝试过。

Regarding deployment it looks like that Azure wants you to prefer Continuous Deployment . 关于部署, Azure希望您喜欢“ Continuous Deployment
The suggested way is this here . 建议的方法是这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM