Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MEAN stack on Ubuntu 14.04 suddenly stopped working

Well, this stinks, here's the scoop:

I'm helping a friend work on a website project using the MEAN stack (mongodb, express, angular and nodejs), I am running Ubuntu 14.04. I'm fairly savvy with Linux and I'm an experienced web developer but most of my experience is with LAMP stack. I've been doing fine plinking away at this MEAN stack project up until this evening. My friend hopped back into developing this evening and I helped them refresh their node env on Mac (they mostly do front end HTML/CSS and I do full stack) by running npm update and the project works fine on their comp. Figuring that I could just as easily refresh my node environment to be more current I tried the same thing:

I attempted to update my node and npm environments because its been a few months since I've done so (I know its bad, I screwed up, I admit it), I think I was using Node.js v 0.3.2.something, didn't think to check version numbers before this chaos ensued. But now I'm getting crazy sets of random errors, unmet dependencies, I can't resolve the unmet dependencies by using npm install to fetch them, and I can't get grunt to launch the dev server, I've tried removing node and npm and reinstalling (now running nodejs 0.10.25) have run apt-get update, apt-get install nodejs, apt-get install nodejs-dev, npm update, npm install, etc., but to no avail.

I'm beyond stuck and beyond frustrated, please help! Here's a sampling of some of the errors/missing dependencies I'm getting:

module.js:340
throw err;
      ^
Error: Cannot find module './helpers'
 at Function.Module._resolveFilename (module.js:338:15)
 at Function.Module._load (module.js:280:25)
 at Module.require (module.js:364:17)
 at require (module.js:380:17)
 at Object.<anonymous>            
 at Module._compile (module.js:456:26)
 at Object.Module._extensions..js (module.js:474:10)
 at Module.load (module.js:356:32)
 at Function.Module._load (module.js:312:12)
 at Module.require (module.js:364:17)
 npm ERR! weird error 8
 npm WARN This failure might be due to the use of legacy binary "node"
 npm WARN For further explanations, please read
 /usr/share/doc/nodejs/README.Debian
 npm ERR! not ok code 0

and when I try and run sudo grunt, I get this:

Loading "jshint.js" tasks...ERROR
>> Error: Cannot find module './name-stack.js'
Loading "grunt-karma.js" tasks...ERROR
>> Error: Cannot find module 'depd'
Warning: Task "jshint" not found. Used --force, continuing.

Running "concurrent:default" (concurrent) task
Loading "jshint.js" tasks...ERROR
>> Error: Cannot find module './name-stack.js'
Loading "jshint.js" tasks...ERROR
>> Error: Cannot find module './name-stack.js'
Loading "grunt-karma.js" tasks...ERROR
Loading "grunt-karma.js" tasks...ERROR
>> Error: Cannot find module 'depd'
>> Error: Cannot find module 'depd'

[Error:           /home/user/Projects/detrashed/node_modules/mongoose/node_modules/mongodb/node_modules/bson/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version
[Error: /home/user/Projects/detrashed/node_modules/connect-  mongo/node_modules/mongodb/node_modules/bson/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version

module.js:340
 throw err;
      ^
Error: Cannot find module './collection/batch/unordered'
  at Function.Module._resolveFilename (module.js:338:15)
  at Function.Module._load (module.js:280:25)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at Object.<anonymous> (/home/user/Projects/detrashed/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/collection.js:21:17)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:364:17)

How embarrassing. Any help or insight into how to unf*ck my nodejs environment would be extremely helpful because I'm about to pull my hair out. Thanks in advance!

like image 251
hypervisor666 Avatar asked Dec 30 '14 09:12

hypervisor666


1 Answers

So first off, I'm sorry you got into this mess. Part of the reason is a bug in npm update -- update does not respect semantic versioning -- but unfortunately it hasn't been fixed yet and keeps biting people. As a result, no-one should ever run npm update and especially never npm update -g.

Also, the official Debian/Ubuntu packages lag the current releases a bit, and there are some nasty race conditions during npm install in the node you get from Debian. Luckily there are packages provided by NodeSource < https://github.com/nodesource/distributions#usage-instructions >

sudo apt-get --purge remove nodejs nodejs-legacy curl -sL https://deb.nodesource.com/setup | sudo bash - sudo apt-get install -y nodejs nodejs-legacy node -v

That should get you the latest node, 0.10.35.

Then update npm

sudo npm install -g npm@latest npm -v

That should get you the latest npm, 2.1.17 (or later).

Now to recover your project. First I would blow away node_modules and run a npm install. If you get any errors from that, please post the complete npm-debug.log file as a gist https://gist.github.com and add the link here.

You may need to re-install the global packages bower and grunt-cli in order to have those in your PATH:

sudo npm i -g bower grunt-cli

One thing to note about npm is that almost all packages will be installed non-globally; only install a package globally if you want it in your command-line PATH.

like image 163
Sam Mikes Avatar answered Sep 22 '22 23:09

Sam Mikes