简体   繁体   English

Node.js项目zip无法上载为Azure WebJob

[英]Node.js project zip failed to upload as Azure WebJob

Please don't close this question without reading. 请不要在没有阅读的情况下关闭此问题。

I have got a regular Node.js project with an index.js and a bunch of node_modules, one of which is azure-storage to download a file.. I have compressed it into .zip and trying to upload it as an Azure WebJob.. but it is failing every time. 我有一个常规的Node.js项目,其中包含一个index.js和一堆node_modules,其中一个是azure-storage来下载文件..我已将其压缩为.zip并尝试将其作为Azure WebJob上传。但每次都失败了。

What it does is, there is one empty directory inside my Node.js project. 它的作用是,我的Node.js项目中有一个空目录。 I have written some code which downloads a csv file from azure storage into the local directory and converts each row into an INSERT statement. 我编写了一些代码,它们将来自azure存储的csv文件下载到本地目录中,并将每一行转换为INSERT语句。

Came across a couple of threads referring to the same prob.. what I have tried is: 遇到了几个涉及同一个问题的线程..我试过的是:

  1. npm dedupe - This was suggested somewhere as node_module directory tree can recursively exceed the length allowed in Windows - Didn't work for me npm重复数据删除 - 这是因为node_module目录树可以递归超过Windows中允许的长度而在某处建议 - 对我来说不起作用
  2. Trashed everything inside node_modules (just to check if #1 is really the problem for me) - Same error 在node_modules中删除了所有内容(只是为了检查#1是否真的对我来说是问题) - 同样的错误
  3. Uploaded the index.js file only - Worked :/ 仅上传index.js文件 - 工作:/

It's been two days and since I didn't see anyone posting a solution here, I gotta assume that no one has run into this problem yet, or maybe very few people are using Node.js + Azure WebJobs. 已经有两天了,因为我没有看到有人在这里发布解决方案,我必须假设没有人遇到过这个问题,或者很少有人使用Node.js + Azure WebJobs。

The good news is, I found the problem and now I have got my Node.js WebJob up and running now inside an Azure App Service. 好消息是,我发现了问题,现在我已经在Azure应用服务中启动并运行了Node.js WebJob。 (And the bad news is I couldn't find anything in the logs I downloaded, not sure if I missed anything in the logs). (坏消息是我在下载的日志中找不到任何内容,不确定我是否遗漏了日志中的任何内容)。

So, here's how I did it, in case anyone tumbles upon the same problem some day... 所以,这就是我如何做到的,以防有人在某一天遇到同样的问题......

First, don't use index.js. 首先,不要使用index.js。 Use run.js as the entry point to your WebJob, and in your package.json file, have the entry { ... "main": "run.js", ... } 使用run.js作为WebJob的入口点,在package.json文件中,使用条目{...“main”:“run.js”,...}

This is pretty simple. 这很简单。

Where I went wrong was, I was compressing my Node.js project directory in to a .zip file and this is where all hell broke loose. 在我出错的地方,我正在将我的Node.js项目目录压缩到一个.zip文件中,这就是所有地狱都崩溃的地方。 Whenever I uploaded this .zip as an Azure WebJob in my App Service.. Azure tried starting it for some time and then ended with an error saying, "failed to add webjob". 每当我在我的应用服务中将此.zip作为Azure WebJob上传时.. Azure尝试启动它一段时间,然后以错误说“无法添加webjob”结束。

Solution: Get into the Node.js project directory and "select all" files + directories inside it and then compress the selection. 解决方案:进入Node.js项目目录并在其中“选择所有”文件+目录,然后压缩选择。 Instead of compressing the Node.js project directory, compress its contents :) 而不是压缩Node.js项目目录,压缩其内容:)

Then upload the compressed .zip as an Azure WebJob in your App Service and it will work like a charm! 然后将压缩的.zip作为Azure WebJob上传到您的App Service中,它将像魅力一样工作!

Some additional info: This is how my Node.js project directory looked like roughly. 一些额外的信息:这是我的Node.js项目目录粗略看起来的样子。

  • _1_my_directory _1_my_directory
  • node_modules node_modules
  • run.js run.js
  • supporting-util-1.js 支撑-UTIL-1.js
  • supporting-util-2.js 支撑-UTIL-2.js
  • app.config 的app.config
  • some-other.config 一些-other.config

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

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