Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure NPM Issue: msnodesql Fails to deploy

I'm trying to set up msnodesql (formerly node-sqlserver) with my azure hosted site and am running into some issues.

Essentially I'm getting a deployment failed within Azure. I believe it is due to the fact NPM is trying to install msnodesql on the server but will fail because it would need "node-gyp", Python and C++ 2010 installed (which is not present on the azure side). Here is the error message I'm seeing

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! `cmd "/c" "node-gyp rebuild"` failed with 1
npm ERR! 
npm ERR! Failed at the [email protected] 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.

I've been hacking at this error for a while now and nothing seems to fix it. The best answer I've gotten is to manually include the msnodesql within node_modules (as specified by http://geekswithblogs.net/shaunxu/archive/2012/11/16/install-npm-packages-automatically-for-node.js-on-windows-azure-web.aspx ). I feel like that should fix it but alas it does not. I also tried compiling it against the local x86 node and also just using a prebuilt x86 one (suggested by http://geekswithblogs.net/shaunxu/archive/2012/09/18/node.js-adventure---when-node.js-meets-windows-azure.aspx ).

Any other suggestions would be appreciated here.

Also worth noting is it's working in my local environment just fine and can grab data in from the SQL Azure DB I created (once i've whitelisted my IP) using msnodesql running within webmatrix but hitting Azure SQL DB.

I originally had an issue with the DB and the Website in Azure being on different regions, but I corrected that.

like image 758
David Gill Avatar asked Jan 20 '13 00:01

David Gill


1 Answers

As Glenn Block mentioned, the problem stems from Azure tyring to build the native module when you deploy. This can happen for a few reasons, maybe you didn't upload the binary, maybe it's the wrong binary, or maybe the deployment directory got screwed up.

The Azure server wants the 32 bit driver for Node .6.

What I had to do was FTP into my azure server and delete everything in /site/wwwroot/ except for web.config. You can probably get away with just deleting node_modules, but because the behavior was unexpected I wanted to clean out everything.

Then I went into my Node project directory on my local machine, and went into the node_module/msnodesql directory and deleted everything but package.json and lib directory. In the lib directory, I created separate directories for the binary for my dev machine(64 bit .8) and azure, called 64 and 32 respectively.

I then modified, sqlserver.native.js as follows

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;
        }
    }
}

The big point to make here is that, we try to load all available versions to accommodate for every possibility of deployment I might have, but give priority to the Azure server. On my local dev machine, we failed to load the node from /32 since it's the wrong format, and we fall back to /64.

I bet if I put a little bit of effort into this, I could easily trim what gets deleted down to the bare minimum, but after wasting hours upon hours resolving this, I had enough.

like image 186
Mike dg Avatar answered Oct 12 '22 04:10

Mike dg