Monday 7 March 2016

Troubleshooting an error in my MEAN app when updating to Node >4.0

I am currently getting an error that is widely reported on the web, however the solutions provided are either a hack (demonstrated below), or do not work for me.I am running the app on Mac (Mavericks), on Node version 0.10.31, and (since I'm assuming this has something to do with them) Mongoose 3.8.x and MongoDB 2.6.7The trouble began when I updated Node and npm to 4.3.2 and 3.8.0 respectively. When I start my server, I get the following error printed in the console, and then the server proceeds to function as normal. { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version From my troubleshooting, it seems like it has something to do with Node, npm, and mongoose. The following advice was what I could find online:1) This is just a warning (not an error), ignore it.Who wants to leave warnings in their code? Besides, this could signify a worse underlying problem with the build.2) bson package nested within the Mongoose module needs python (wtf?) to build. Ensure python is set to version between 2.5 and 3 (exclusive).I'm not experienced enough to figure out what python has to do with the build, but my python is version 2.7.5.3) Go into the deeply nested bson package in node_modules and change a line in the index.js file from require('../build/Release/bson') to require('bson')Haven't, nor will I, try this approach. This is a hacky fix that will cause problems on future npm module installs/upgrades.4) run "rm -rf node_modules && npm cache clean && npm install"This seemed to be a fix for a lot of people online, but unfortunately, it does not fix the problem for me (but it does help: see below)So far, I have npm installed n so that I can play around with different Node versions, as well as different npm versions. Every time I switch to a different combination of versions, I run the line from advice #4 to rebuild the node_modules folder.So far, I've found that when I go back to Node 0.10.x, I do not get the error message, no matter what version of npm I use (at least, not with 2.14.x and 3.8.0).I do get the error with Node 4.3.2 and 5.6.0, regardless of npm version. So it seems like npm is not the problem.Hopefully this was enough information to go on. Has anyone else experienced this problem or know what's going on?In the meantime, I'm going to try updating mongoose to 4.x, as it's likely due to Mongoose not up to date with Node's recent changes.

Submitted March 07, 2016 at 10:41PM by ubccompscistudent

No comments:

Post a Comment