Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting "Segmentation fault: 11" from NodeJS after 4.0 update

I just reinstalled NodeJS. Prior to the reinstall, when I ran node -v I got a version number that said something like "0.2.x"... It was a weird number. And since I read this morning Node was just updated to version 4.x.x I thought I should update it. Also, I was having other problems, so I thought that this might be the reason for that.

When I run the following server.js I get the following console print out.

server.js...

var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var _ = require('lodash');

// Create the application.
var app = express();

// Add Middleware necessary for REST API's
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(methodOverride('X-HTTP-Method-Override'));

// CORS Support
app.use(function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  next();
});

// Connect to MongoDB
mongoose.connect('mongo connection string......');
mongoose.connection.once('open', function() {

  // Load the models.
  app.models = require('./models/index');

  // Load the routes.
  var routes = require('./routes');
  _.each(routes, function(controller, route) {
    app.use(route, controller(app, route));
  });

  console.log('Listening on port 3000...');
  app.listen(3000);
});

The console prints the following after I run node --debug server.js

Debugger listening on port 5858
Segmentation fault: 11

Edit: I have another project that is based off of MEANJS. When I run the Gruntfile.js I get a Segmentation fault: 11 from the console.

Edit #2: I just downgraded to node v0.12.7 and things seem to be working normal...

like image 601
ryndshn Avatar asked Sep 09 '15 02:09

ryndshn


2 Answers

I believe you need to reinstall some native lib in node_modules, so basically might need to remove node_modules, and npm install again.

Also npm cache clean might need to run, before install.

like image 77
YOU Avatar answered Sep 26 '22 15:09

YOU


Before deleting node_modules and then running npm install again, try npm rebuild. It will re-compile native modules for the new version of Node/V8 you have installed without having to download all the files again.

npm rebuild should work. But if it doesn't, then try deleting node_modules and running npm install as a nuclear option.

like image 36
Trott Avatar answered Sep 26 '22 15:09

Trott