node.js - Azure NPM 问题 : msnodesql Fails to deploy

标签 node.js azure azure-sql-database

我正在尝试使用我的 Azure 托管站点设置 msnodesql(以前称为 Node-sqlserver),但遇到了一些问题。

基本上,我在 Azure 中部署失败。我相信这是因为 NPM 试图在服务器上安装 msnodesql 但会失败,因为它需要安装“node-gyp”、Python 和 C++ 2010( azure 方面不存在)。这是我看到的错误消息

npm ERR! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cf1eff2f3f8f9efedf0dcacb2aeb2ac" rel="noreferrer noopener nofollow">[email protected]</a> install: `node-gyp rebuild`
npm ERR! `cmd "/c" "node-gyp rebuild"` failed with 1
npm ERR! 
npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7518061b1a111006041935455b475b45" rel="noreferrer noopener nofollow">[email protected]</a> install script.
npm ERR! This is most likely a problem with the msnodesql package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls msnodesql
npm ERR! There is likely additional logging output above.

我已经解决这个错误有一段时间了,但似乎没有什么可以解决它。我得到的最佳答案是手动将 msnodesql 包含在 node_modules 中(由 http://geekswithblogs.net/shaunxu/archive/2012/11/16/install-npm-packages-automatically-for-node.js-on-windows-azure-web.aspx 指定)。我觉得这应该解决它,但可惜没有。我还尝试针对本地 x86 Node 编译它,并且仅使用预构建的 x86 Node (由 http://geekswithblogs.net/shaunxu/archive/2012/09/18/node.js-adventure---when-node.js-meets-windows-azure.aspx 建议)。

如有任何其他建议,我们将不胜感激。

还值得注意的是,它在我的本地环境中工作得很好,并且可以使用在 webmatrix 中运行的 msnodesql 但访问 Azure SQL DB 从我创建的 SQL Azure DB 中获取数据(一旦我将我的 IP 列入白名单)。

我最初遇到了 Azure 中的数据库和网站位于不同区域的问题,但我已更正了该问题。

最佳答案

正如 Glenn Block 提到的,问题源于部署时 Azure 需要构建 native 模块。发生这种情况的原因有多种,可能是您没有上传二进制文件,可能是错误的二进制文件,也可能是部署目录搞砸了。

Azure 服务器需要 Node .6 的 32 位驱动程序。

我要做的就是通过 FTP 进入我的 azure 服务器并删除/site/wwwroot/中除 web.config 之外的所有内容。您可能只需删除 node_modules 就可以逃脱惩罚,但由于该行为是意外的,我想清除所有内容。

然后我进入本地计算机上的 Node 项目目录,进入 node_module/msnodesql 目录并删除除 package.json 和 lib 目录之外的所有内容。在 lib 目录中,我为我的开发机器(64 位 .8)和 azure 的二进制文件创建了单独的目录,分别称为 64 和 32。

然后我修改了sqlserver.native.js如下

try {
    module.exports = require('./32/sqlserver.node'); //Azure version
}
catch (e) {
    try {
        module.exports = require('./64/sqlserver.node'); //My local machine
    }
    catch (e) {
        try {
            module.exports = require('../build/Release/sqlserver.node');
        }
        catch (e) {
            console.error('Native sqlserver module not found. Did you remember to run node-gyp configure build?');
            throw e;
        }
    }
}

这里要强调的重点是,我们尝试加载所有可用版本以适应我可能拥有的每种部署可能性,但优先考虑 Azure 服务器。在我的本地开发计算机上,我们无法从/32 加载 Node ,因为它的格式错误,我们回退到/64。

我敢打赌,如果我为此付出一点努力,我可以轻松地将删除的内容削减到最低限度,但在浪费了几个小时解决这个问题之后,我已经受够了。

关于node.js - Azure NPM 问题 : msnodesql Fails to deploy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14420387/

相关文章:

javascript - 如何在 for 循环中等待异步查询完成?

javascript - 有没有办法将选项存储在变量中?

powershell - 如何在arm模板中配置APNS.Certificate

Azure 资源组 - 如何判断哪些是 "related"?

sql-server - SQL Azure - SSMS - 从服务器接收结果时发生传输级错误

java - Spring Hibernate 无法连接到名称中带有连字符的 SQL Server

node.js - 无法弄清楚如何在 Bot Service 上生成和查看 Node Js bot 的日志

php - Azure 表存储响应时间慢

vb.net - RetryPolicy.Retrying 事件在 SQL Azure 的 transient 错误处理期间未触发?

json - 如何将已解决的 promise 值传递给另一个函数?