Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module.js:338 throw err in node.js

Tags:

node.js

I'm using ubuntu and I'm trying to run a script using nodejs and i'm getting this error.

/home/bebz/Documents/test# node server.js
module.js:338
throw err;
      ^
Error: Cannot find module 'merge-descriptors'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/bebz/node_modules/express/lib/express.js:6:13)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

What is the problem? I'm in the right directory and also i tried to run it using root but nothing happens.

Inside server.js is

// get dependencies
var app = require("express")();

// handle request and response
app.get("/", function(req, res) {
    res.send({name:"Hello Wolrd"});
});

// initializing a port
app.listen( 5000);

A simple example just to show that node.js is working.

like image 567
Abdullah Avatar asked Feb 07 '15 01:02

Abdullah


2 Answers

It seems like the script has an unmet dependency - meaning you have to install the module "merge-descriptors" first.

It also seems like the script is using "express" (and "merge-descriptors" actually looks like a dependency of "express") - because this didn't throw an error some dependencies seem to be installed already.

So you could try to install the missing ones via npm install or npm update.

Update: According to npmjs.org "merge-descriptors" is an dependency of "express". Looking at your stacktrace shows that you have "express" installed globally - so you should try npm update -g

If that doesn't solve your problem you should have a look at this question.

like image 50
Florian Loch Avatar answered Oct 21 '22 06:10

Florian Loch


npm update

I see this when the module install order is not perfect, or multiple modules exist.

npm update sorts this out deprecating the incorrect versions.

like image 41
Andy Carr Avatar answered Oct 21 '22 07:10

Andy Carr